File tree Expand file tree Collapse file tree 3 files changed +41
-8
lines changed
Expand file tree Collapse file tree 3 files changed +41
-8
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ class Slider extends React.Component {
2323 }
2424
2525 render ( ) {
26- if ( this . props . range . min === this . props . range . max ) {
27- // There's no need to try to render the Slider, it will not be usable
28- // and will throw
29- return null ;
30- }
26+ // display a `disabled` state of the `NoUiSlider` when range.min === range.max
27+ const { range : { min, max} } = this . props ;
28+ const isDisabled = min === max ;
29+
30+ // when range.min === range.max, we only want to add a little more to the max
31+ // to display the same value in the UI, but the `NoUiSlider` wont
32+ // throw an error since they are not the same value.
33+ const range = isDisabled
34+ ? { min, max : min + 0.0001 }
35+ : { min, max} ;
3136
3237 // setup pips
3338 let pips ;
@@ -48,12 +53,14 @@ class Slider extends React.Component {
4853 < Nouislider
4954 // NoUiSlider also accepts a cssClasses prop, but we don't want to
5055 // provide one.
51- { ...omit ( this . props , [ 'cssClasses' ] ) }
56+ { ...omit ( this . props , [ 'cssClasses' , 'range' ] ) }
5257 animate = { false }
5358 behaviour = { 'snap' }
5459 connect
5560 cssPrefix = { cssPrefix }
5661 onChange = { this . handleChange }
62+ range = { range }
63+ disabled = { isDisabled }
5764 pips = { pips }
5865 />
5966 ) ;
Original file line number Diff line number Diff line change @@ -47,10 +47,27 @@ describe('Slider', () => {
4747 ) ;
4848 } ) ;
4949
50- it ( 'should not render anything when ranges are equal' , ( ) => {
50+ it ( 'should render <NouisLider disabled="true" /> when ranges are equal' , ( ) => {
5151 props . range . min = props . range . max = 8 ;
5252 const out = render ( ) ;
53- expect ( out ) . toEqual ( null ) ;
53+ expect ( out ) . toEqualJSX (
54+ < Nouislider
55+ animate = { false }
56+ behaviour = "snap"
57+ connect
58+ cssPrefix = "ais-range-slider--"
59+ format = { { to : ( ) => { } , from : ( ) => { } } }
60+ onChange = { ( ) => { } }
61+ pips = { {
62+ density : 3 ,
63+ mode : 'positions' ,
64+ stepped : true ,
65+ values : [ 0 , 50 , 100 ] ,
66+ } }
67+ range = { { min : props . range . min , max : props . range . min + 0.0001 } }
68+ disabled
69+ />
70+ ) ;
5471 } ) ;
5572
5673 function render ( ) {
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ $range-slider-handle-bg: $white;
1616 height : $range-slider-target-height ;
1717 margin-top : 2em ;
1818 margin-bottom : 2em ;
19+
20+ & [disabled = " true" ] {
21+ cursor : not-allowed ;
22+
23+ .ais-range-slider--handle {
24+ border-color : $range-slider-marker-bg ;
25+ cursor : not-allowed ;
26+ }
27+ }
1928 }
2029
2130 @include element (base) {
You can’t perform that action at this time.
0 commit comments