Comments (23)
Hm, very recently i implement this. 0.2.9 version, 0.3.2 is latest. Can you check again or help reproduce issue on jsbin or somewhere?
from react-horizontal-scrolling-menu.
I have the same issue, I cannot programmatically, without click change active tab
from react-horizontal-scrolling-menu.
Ok, what happen if update parent component?
Select it in react console and update
$r.forceUpdate()
from react-horizontal-scrolling-menu.
what should I update? I have 2 components, redux store in which I store the name of active item. If I change this name in redux, it didn't change in the scrollable menu, but in the selected property goes correct data
from react-horizontal-scrolling-menu.
Can you reproduce it?
from react-horizontal-scrolling-menu.
I will try to reproduce tomorrow but idea is to change tab during certain condition. For example I setState item with number 1 and give it to selected prop of menu and it should change it. But it changes it only if I click on the item
from react-horizontal-scrolling-menu.
const list = [
{ name: 'item1' },
{ name: 'item2' },
{ name: 'item3' },
{ name: 'item4' },
{ name: 'item5' },
{ name: 'item6' },
{ name: 'item7' },
{ name: 'item8' },
{ name: 'item9' },
{ name: 'item10' },
{ name: 'item11' },
{ name: 'item12' },
{ name: 'item13' },
{ name: 'item14' },
{ name: 'item15' },
{ name: 'item16' },
{ name: 'item17' },
{ name: 'item18' },
{ name: 'item19' },
{ name: 'item20' },
{ name: 'item21' },
{ name: 'item22' },
{ name: 'item23' },
{ name: 'item24' },
{ name: 'item25' }
];
const MenuItem = ({ text, selected }) => {
return (
<div
className={`${Styles.menu_item} ${selected ? Styles.active : ''}`}
>
{text}
</div>
);
};
export const Menu = (list) => list.map(el => {
const { name } = el;
return (
<MenuItem
text={name}
key={name}
/>
);
});
const Arrow = ({ text, className }) => {
return (
<div
className={className}
>{text}</div>
);
};
export const ArrowLeft = Arrow({ text: '<', className: 'arrow-prev' });
export const ArrowRight = Arrow({ text: '>', className: 'arrow-next' });
class TabComponent extends Component {
constructor(props) {
super(props);
this.menu = null;
this.state = {
selected: 'item1',
itemsCount: list.length,
translate: 0,
alignCenter: true,
dragging: true,
clickWhenDrag: false,
transition: 0.4,
wheel: true
};
this.menuItems = Menu(list.slice(0, list.length), this.state.selected);
}
onUpdate = ({ translate }) => {
console.log(`onUpdate: translate: ${translate}`);
this.setState({ translate });
}
onSelect = key => {
console.log(`onSelect: ${key}`);
this.setState({ selected: key });
}
componentDidUpdate(prevProps, prevState) {
const { alignCenter } = prevState;
const {
alignCenter: alignCenterNew
} = this.state;
if (alignCenter !== alignCenterNew) {
this.menu.setInitial();
}
}
setItemsCount = ev => {
const { itemsCount = list.length, selected } = this.state;
const val = +ev.target.value;
const itemsCountNew = !isNaN(val) && val <= list.length && val >= 0
? +ev.target.value
: list.length;
const itemsCountChanged = itemsCount !== itemsCountNew;
if (itemsCountChanged) {
this.menuItems = Menu(list.slice(0, itemsCountNew), selected);
this.setState({
itemsCount: itemsCountNew});
}
}
setSelected = ev => {
const { value } = ev.target;
this.setState({ selected: String(value) });
}
test = () => {
console.log(`onSelect: item12`);
this.setState({ selected: 'item12' });
}
render() {
const {
selected,
translate,
alignCenter,
dragging,
clickWhenDrag,
transition,
wheel,
itemsCount
} = this.state;
const menu = this.menuItems;
const checkboxStyle = {
margin: '5px 10px'
};
const valueStyle = {
margin: '5px 10px',
display: 'inline-block'
};
return (
<div className="App">
<header className="App-header">
<h1 onClick={this.test} className="App-title">React horizontal scrolling menu</h1>
</header>
<p className="App-intro" onClick={this.test}>
Horizontal scrolling menu example.
Click arrow or drag items.
</p>
<ScrollMenu
ref={el => this.menu = el}
data={menu}
arrowLeft={ArrowLeft}
arrowRight={ArrowRight}
transition={+transition}
onUpdate={this.onUpdate}
onSelect={this.onSelect}
selected={selected}
translate={translate}
alignCenter={alignCenter}
dragging={false}
clickWhenDrag={clickWhenDrag}
wheel={wheel}
/>
</div>
)
}
}
so using this snippet from your repo I can reproduce that bug. I want to set programatically active tab clicking on test onclick function, when I click state updates but tab item doesn't change
from react-horizontal-scrolling-menu.
Reproduce i mean create snipper here for example https://codesandbox.io
In demo project now can change selected item from parent component and it works.
clicking on test onclick function
Don't understand what you mean, need just pass new value in selected prop.
Example
It works, show exactly where is problem
from react-horizontal-scrolling-menu.
I need to add code snippet from my code that. I will add it tomorrow and share it
from react-horizontal-scrolling-menu.
Look at my example, "selected" text field, change 'item1' to 'item2' and selected item changes.
Anyway, i steel need working snippet when i can see problem, not text or description.
In my last message has link where you can easily create it.
from react-horizontal-scrolling-menu.
Yes, I saw this, but for some reason in my component it doesn't work. I will create code snippet tomorrow. Maybe the problem is because I set active menu item in one component and pass it into other component where actually menu is
from react-horizontal-scrolling-menu.
So need check passed props from your component and how it update, prop doesn't update or component doesn't update.
from react-horizontal-scrolling-menu.
I pass them via redux, they come to component for sure, I checked this but menu doesn't update
from react-horizontal-scrolling-menu.
Make repo where i can see problem.
from react-horizontal-scrolling-menu.
so I created sandbox here https://codesandbox.io/s/wyk4pn0vow but the thing is that in the sandbox everything working as expected but locally it isn't. I debugged everything and the thing is when I update selected menu item in state, state updates, Menu function running but MenuItem function isn't, item didn't changes through selected prop but state already contains changed menu item
from react-horizontal-scrolling-menu.
Sandbox is empty.
Try to update to latest version.
from react-horizontal-scrolling-menu.
https://codesandbox.io/s/wyk4pn0vow
from react-horizontal-scrolling-menu.
did you update the component?
from react-horizontal-scrolling-menu.
From 0.2.9 version must work.
from react-horizontal-scrolling-menu.
Yes, it was the reason. I used 0.2.7 version. Thanks
from react-horizontal-scrolling-menu.
Hi, asmyshlyaev177.
Sorry for delay in response.
It seems that your component is working. I just misunderstood behaviour of selecting items. As for me, if item is selected - the whole container should be scrolled until selected item becomes visible.
What do you think about it?
from react-horizontal-scrolling-menu.
Hi, already has issue about that, will implement later.
from react-horizontal-scrolling-menu.
I mentioned the same that @markoffk speaking about in this ticket #14
from react-horizontal-scrolling-menu.
Related Issues (20)
- Could not find a declaration file for module 'react-horizontal-scrolling-menu'. HOT 1
- Vertically Scrolling Feature HOT 5
- Update readme HOT 2
- 'Arrow' component is not defined. HOT 1
- [BUG]To many rerenders HOT 3
- Update `smooth-scroll-into-view-if-needed` to latest version HOT 1
- Testing issues HOT 1
- [ERROR] Could not resolve "smooth-scroll-into-view-if-needed" HOT 4
- Export Context Provider as seperate component HOT 1
- Ability to animate children HOT 10
- How to prevent to scroll on scroll menu position when scrollPrev or scrollNext called. HOT 2
- Scroll item to center but don't scroll the whole page so the item is in view. HOT 4
- Issue with scroll on grab - div doesn't stop scrolling once the cursor exits scrollable area [BUG] HOT 2
- [BUG] Scroll doesn't work when the hight of Cards are higher than viewport HOT 3
- Is it impossible to use it in the server component? HOT 1
- [BUG] Show and Hide Button Arrows HOT 1
- Docs are outdated (visibleElements and initComplete) HOT 1
- [BUG] Import package HOT 5
- [BUG] Arrows appear when scrolling on the Y-axis HOT 4
- Use swipe in desktop HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-horizontal-scrolling-menu.