zillow / react-slider

Accessible, CSS agnostic, slider component for React.
https://zillow.github.io/react-slider
MIT License
892 stars 231 forks source link

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

Closed jshthornton closed 6 years ago

jshthornton commented 7 years ago

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 commented 7 years ago

Can confirm!

Artforge commented 7 years ago

+1

hennadiy-kudashev commented 7 years ago

+1

caseybaggz commented 7 years ago

Same.

martinschnurer commented 7 years ago

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 commented 7 years ago

@mpowaga do you have plans on updating to v16 in the near future?

erosenberg commented 6 years ago

This is happening for me too!

laurenkt commented 6 years ago

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 commented 6 years ago

See https://github.com/mpowaga/react-slider/pull/114 for a fix

mpowaga commented 6 years ago

Fixed in version 0.10.0.