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

How can I disable slider ? #109

Open
HeratPatel1 opened this issue Feb 12, 2018 · 4 comments
Open

How can I disable slider ? #109

HeratPatel1 opened this issue Feb 12, 2018 · 4 comments

Comments

@HeratPatel1
Copy link

If I want to disable my slider, is there any props available for that ?
I update my slider with web-socket.
thanks in advance.

@slnsrn
Copy link

slnsrn commented Mar 27, 2018

I fixed it with return. Style is the same but it is ok.

durationChangeCallback = (duration) => {
     if (this.state.is_started) {
          return; // kind of disable 
     }else{
          this.setState({duration});
    }
}

@champi-dev
Copy link

I did it like this:

<Slider
    orientation='horizontal'
    min={1}
    max={5}
    labels={this.state.labels}
    value={this.state.sliderValue}
    onChange={(newValue) => {}}
/>

@pranay202
Copy link

pranay202 commented Sep 5, 2021

React library already provides disable props. You need to make following changes in your code.

Make constructor with isDisable state with default false value

constructor(props){
super(props);
this.state={
isDisable:false
}

}

Add a function into onChange callback props

_checkMaximunSliderValue=(value)=>{
 If(value==100){ 
this.setState({isDisable:true})
}
}

Set this.state.isDisable in disable props

<VerticalSlider
  value={1}
  disabled={this.state.isDisable}
  min={0}
  max={100}
  onChange={(value: number) => {
    this._checkMaximunSliderValue(value);
  }}
  onComplete={(value: number) => {
    console.log("COMPLETE", value);
  }}
  width={50}
  height={300}
  step={1}
  borderRadius={5}
  minimumTrackTintColor={"gray"}
  maximumTrackTintColor={"tomato"}
  showBallIndicator
  ballIndicatorColor={"gray"}
  ballIndicatorTextColor={"white"}
/>;

@jivansupe
Copy link

jivansupe commented Apr 7, 2022

You can simply add a disabled class as an additional class when you need to disable the slider. Worked for me.

.disabled {
   pointer-events: none;
   opacity: 0.7;
}

<Slider className={isDisabled ? "disabled" : ''}
            min={0}
            max={100}
            value={volume}
            onChange={handleChange}
            onChangeStart={handleChangeStart}
            onChangeComplete={handleChangeComplete}
/>

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

No branches or pull requests

5 participants