@@ -47,65 +47,6 @@ export default class MultiSlider extends React.Component {
47
47
minMarkerOverlapDistance : 0 ,
48
48
} ;
49
49
50
- static getDerivedStateFromProps ( props , state ) {
51
- const {
52
- onePressed,
53
- twoPressed,
54
- min,
55
- max,
56
- step,
57
- sliderLength,
58
- valueOne,
59
- valueTwo,
60
- optionsArray,
61
- } = state ;
62
- if ( onePressed || twoPressed ) {
63
- return null ;
64
- }
65
-
66
- let nextState = { } ;
67
-
68
- if (
69
- props . min !== min ||
70
- props . max !== max ||
71
- props . step !== step ||
72
- props . values [ 0 ] !== valueOne ||
73
- props . sliderLength !== sliderLength ||
74
- props . values [ 1 ] !== valueTwo ||
75
- ( props . sliderLength !== sliderLength && props . values [ 1 ] )
76
- ) {
77
- this . optionsArray =
78
- optionsArray || createArray ( props . min , props . max , props . step ) ;
79
-
80
- this . stepLength = sliderLength / this . optionsArray . length ;
81
-
82
- const positionOne = valueToPosition (
83
- props . values [ 0 ] ,
84
- this . optionsArray ,
85
- props . sliderLength ,
86
- ) ;
87
- nextState . valueOne = props . values [ 0 ] ;
88
- nextState . pastOne = positionOne ;
89
- nextState . positionOne = positionOne ;
90
-
91
- const positionTwo = valueToPosition (
92
- props . values [ 1 ] ,
93
- this . optionsArray ,
94
- props . sliderLength ,
95
- ) ;
96
- nextState . valueTwo = props . values [ 1 ] ;
97
- nextState . pastTwo = positionTwo ;
98
- nextState . positionTwo = positionTwo ;
99
- }
100
-
101
- if ( nextState != { } ) {
102
- return {
103
- ...state ,
104
- ...nextState ,
105
- } ;
106
- }
107
- }
108
-
109
50
constructor ( props ) {
110
51
super ( props ) ;
111
52
@@ -368,11 +309,12 @@ export default class MultiSlider extends React.Component {
368
309
) ;
369
310
} ;
370
311
371
- componentDidUpdate ( _ , prevState ) {
312
+ componentDidUpdate ( prevProps , prevState ) {
372
313
const {
373
314
positionOne : prevPositionOne ,
374
315
positionTwo : prevPositionTwo ,
375
316
} = prevState ;
317
+
376
318
const { positionOne, positionTwo } = this . state ;
377
319
378
320
if (
@@ -385,6 +327,48 @@ export default class MultiSlider extends React.Component {
385
327
if ( positionOne !== prevPositionOne || positionTwo !== prevPositionTwo ) {
386
328
this . props . onMarkersPosition ( [ positionOne , positionTwo ] ) ;
387
329
}
330
+
331
+ if ( this . state . onePressed || this . state . twoPressed ) {
332
+ return ;
333
+ }
334
+
335
+ let nextState = { } ;
336
+ if (
337
+ prevProps . min !== this . props . min ||
338
+ prevProps . max !== this . props . max ||
339
+ prevProps . step !== this . props . step ||
340
+ prevProps . values [ 0 ] !== this . props . values [ 0 ] ||
341
+ prevProps . sliderLength !== this . props . sliderLength ||
342
+ prevProps . values [ 1 ] !== this . props . values [ 1 ] ||
343
+ ( prevProps . sliderLength !== this . props . sliderLength &&
344
+ prevProps . values [ 1 ] )
345
+ ) {
346
+ this . optionsArray =
347
+ this . props . optionsArray ||
348
+ createArray ( this . props . min , this . props . max , this . props . step ) ;
349
+
350
+ this . stepLength = this . props . sliderLength / this . optionsArray . length ;
351
+
352
+ const positionOne = valueToPosition (
353
+ this . props . values [ 0 ] ,
354
+ this . optionsArray ,
355
+ this . props . sliderLength ,
356
+ ) ;
357
+ nextState . valueOne = this . props . values [ 0 ] ;
358
+ nextState . pastOne = positionOne ;
359
+ nextState . positionOne = positionOne ;
360
+
361
+ const positionTwo = valueToPosition (
362
+ this . props . values [ 1 ] ,
363
+ this . optionsArray ,
364
+ this . props . sliderLength ,
365
+ ) ;
366
+ nextState . valueTwo = this . props . values [ 1 ] ;
367
+ nextState . pastTwo = positionTwo ;
368
+ nextState . positionTwo = positionTwo ;
369
+
370
+ this . setState ( nextState ) ;
371
+ }
388
372
}
389
373
390
374
render ( ) {
0 commit comments