-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle doesn't start at the correct position in React 16 #115
Comments
Can confirm! |
+1 |
1 similar comment
+1 |
Same. |
Ugly workaround for controlled slider: const defaultValues = [20, 30, 40]
class Home extends React.Component {
constructor () {
super()
this.state = { value: defaultValues }
}
componentDidMount () {
setTimeout(() => this.setState({
value: defaultValues
}), 1)
}
render () {
<ReactSlider value={this.state.value} onChange={value => this.setState({value})}>
<div className="my-handle">1</div>
<div className="my-handle">2</div>
<div className="my-handle">3</div>
</ReactSlider>
}
} |
@mpowaga do you have plans on updating to v16 in the near future? |
misino
added a commit
to misino/react-slider
that referenced
this issue
Oct 24, 2017
Even if component is defined with defaultValue bigger than 0, the handle can be rendered at position `left: 0px`. The render method of react-slider component is called twice at the beginning because of handleResize event which calls setState. On first render, it calculates left as 0, second render sets correct left value. The issue occurs in React version 16, which implements optimized diffing of DOM changes. Handle components are not rerendered second time, because they are returned as mutated tempArray. It means that the object reference of handle components is not changed between first and second render. And react 16 evaluates it as no change DOM change.
This is happening for me too! |
As an alternative to @martinschnurer's workaround if you are using props instead of state, or if you just want to avoid referencing your initial state twice, you can just do this on your component: componentDidMount () {
setTimeout(() => this.forceUpdate(), 1)
} |
See #114 for a fix |
Fixed in version 0.10.0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using react 16 the handle does not start at the position you give it.
For example:
The handle will be at 0 and not draggable until you click on the bar.
The text was updated successfully, but these errors were encountered: