Skip to content
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

Closed
jshthornton opened this issue Oct 13, 2017 · 10 comments · Fixed by #121
Closed

Handle doesn't start at the correct position in React 16 #115

jshthornton opened this issue Oct 13, 2017 · 10 comments · Fixed by #121

Comments

@jshthornton
Copy link

jshthornton commented Oct 13, 2017

When using react 16 the handle does not start at the position you give it.

For example:

<ReactSlider
  min={0}
  max={10}
  value={5}
>
  <div/>
</ReactSlider>

The handle will be at 0 and not draggable until you click on the bar.

@Nesciosquid
Copy link

Can confirm!

@Artforge
Copy link

+1

1 similar comment
@hennadiy-kudashev
Copy link

+1

@caseybaggz
Copy link

Same.

@martinschnurer
Copy link

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>   
  }
}

@caseybaggz
Copy link

@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.
@erosenberg
Copy link

This is happening for me too!

@laurenkt
Copy link

laurenkt commented Jan 9, 2018

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)
}

@lukashlavacka
Copy link

See #114 for a fix

@mpowaga
Copy link
Contributor

mpowaga commented Feb 28, 2018

Fixed in version 0.10.0.

@mpowaga mpowaga closed this as completed Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants