Skip to content

Disable functionality? #51

Answered by nerdyman
nigow asked this question in Q&A
Aug 10, 2021 · 3 comments · 5 replies
Discussion options

You must be logged in to vote

Hey @nigow!

There's no built in functionality disable the slider at the moment but it should be simple enough to do with a custom pointer event.

I've hacked together a quick demo that applies its own onPointerDown binding to the slider which prevents the slider from moving when enabled is false. enabled is toggled by a button in the top left of the demo.

return (
	<ReactCompareSlider
	  	  // ...
	      onPointerDown={(ev) => {
	        if (!enabled) {
	          ev.preventDefault();
	        }
	      }}
	/>
)

https://codesandbox.io/s/react-compare-slider-disable-enable-slider-qk8pb?file=/src/App.jsx:886-1035

Let me know if this does what you need.

*Edit I changed the demo so it disables …

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@nigow
Comment options

Answer selected by nerdyman
Comment options

You must be logged in to vote
4 replies
@nerdyman
Comment options

@rsumit123
Comment options

@nerdyman
Comment options

@rsumit123
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request has workaround Issue has a viable workaround released Issue resolved and published
3 participants