How do I reset values for slider
I have a slider as below which uses marks for custom dates. Sliding functionality is working. Once slider moves and certain point I want to reset slider to defult values after some action (For e.g Button click).
There is not reset or custom method option in props which I can use. What is the best way to do that?
Original Slider :

User Changes Slider to :

After reset button click it need to go back to :

Use prop value to convert Slider to a controlled component.
I have the same issue. As soon as I use the value prop, I am unable to grab the slider handles.
@yesmeck Do you perhaps have an example solution for this use case specific to rc-slider?
@sandervanhooft See https://github.com/ant-design/ant-design/wiki/FAQ#i-set-the-value-of-inputselectetc-and-then-it-cannot-be-changed-by-users-action
@yesmeck This is a little bit confusing. Changing defaultValue makes a lot of sense, but the component's componentWillReceiveProps() ignores changes to defaultValue. Thus the component won't rerender. Is this a bug, or expected behavior? If it's expected, then I'm confused on how to accomplish the goal outlined by the OP.
defaultValue is not considered to change, if you want change value of slider, use value. See
https://facebook.github.io/react/docs/forms.html#controlled-components https://facebook.github.io/react/docs/uncontrolled-components.html
@yesmeck but if I set value the user can't make further edits. Here is a fiddle: if I change defaultValue to value then slider is locked in place. Perhaps I'm being dense, but I don't see how using an uncontrolled component would help, since then I wouldn't be able to actually set it. (Another fiddle). What am I missing?
but I don't see how using an uncontrolled component would help
Then you should use controlled component.
@yesmeck that's my first fiddle though, right? I think I must be missing something more basic here.
No, your first fiddle is still a uncontrolled component. A controlled component means you pass value to the component and use onChange to collect the component value to the state.
See http://codepen.io/yesmeck/pen/evaJPP?editors=0010
Ah, OK, I get it now. Thanks for your time!
@yesmeck thanks, I implemented and it works so fine!
No, your first fiddle is still a uncontrolled component. A controlled component means you pass
valueto the component and useonChangeto collect the component value to thestate.See http://codepen.io/yesmeck/pen/evaJPP?editors=0010
awesome, thanks!
I just faced this issue in my project. Following solution may help you.
Scenario: The project is in React-nextJS framework. We have to use recommended client components. There is price slider component called as RangeSelector on one page. The issue was that on resetting that RangeSelector, functionally wise it works well but on slider it was showing same last searched values and slider point tip. that is it was showing previous min max values.
Solution:
RangeSelector is in child component. In RangeSelector component, two JSX attributes - key & onAfterChange - used like:
key={props.onReseTrue} & onAfterChange(e, props.min_val, props.max_val) }}. These are defined in main component as follows:
function onAfterChange(data,minVal,maxVal) {
data.minval=minVal;
data.maxval=maxVal;
}
Important : We used a prop "key" in RangeSelector slider component and set its value true on clicking reset button.
Pass both these values as props to child component. This way solved Range Slider reset issue.