@@ -126,7 +126,6 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
126
126
127
127
private _numberInputs : HTMLInputElement [ ] ;
128
128
private _rangeInputs : HTMLInputElement [ ] ;
129
- private _ready : Boolean = false ;
130
129
private _valuesGap : number = 1 ;
131
130
private _suppressAttributeChange : boolean = false ;
132
131
@@ -137,6 +136,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
137
136
this . _suppressAttributeChange = true ;
138
137
this . setAttribute ( 'value-min' , value . toString ( ) ) ;
139
138
this . _suppressAttributeChange = false ;
139
+ this . _updateInputValues ( ) ;
140
+ this . _updateRangeInputsValues ( ) ;
140
141
}
141
142
142
143
public get valueMax ( ) {
@@ -146,6 +147,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
146
147
this . _suppressAttributeChange = true ;
147
148
this . setAttribute ( 'value-max' , value . toString ( ) ) ;
148
149
this . _suppressAttributeChange = false ;
150
+ this . _updateInputValues ( ) ;
151
+ this . _updateRangeInputsValues ( ) ;
149
152
}
150
153
151
154
public get min ( ) {
@@ -155,6 +158,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
155
158
this . _suppressAttributeChange = true ;
156
159
this . setAttribute ( 'min' , value . toString ( ) ) ;
157
160
this . _suppressAttributeChange = false ;
161
+ this . _updateRangeInputsMinMax ( ) ;
158
162
}
159
163
160
164
public get max ( ) {
@@ -164,21 +168,19 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
164
168
this . _suppressAttributeChange = true ;
165
169
this . setAttribute ( 'max' , value . toString ( ) ) ;
166
170
this . _suppressAttributeChange = false ;
171
+ this . _updateRangeInputsMinMax ( ) ;
167
172
}
168
173
169
174
attributeChangedCallback ( name : string , oldValue : string , newValue : string ) {
170
175
if ( this . _suppressAttributeChange ) return ;
171
- if ( name == "value-min" ) {
172
- this . _valueMinAttributeChanged ( ) ;
173
- }
174
- if ( name === "value-max" ) {
175
- this . _valueMaxAttributeChanged ( ) ;
176
- }
177
- if ( name == "min" ) {
178
- this . _minAttributeChanged ( ) ;
176
+ if ( name === "value-min" || name === "value-max" ) {
177
+ this . _updateInputValues ( ) ;
178
+ this . _updateRangeInputsValues ( ) ;
179
+ this . _updateSliderPosition ( parseInt ( this . valueMin ) , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
180
+ this . _updateSliderPosition ( parseInt ( this . valueMax ) , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
179
181
}
180
- if ( name === "max" ) {
181
- this . _maxAttributeChanged ( ) ;
182
+ if ( name === "min" || name === " max") {
183
+ this . _updateRangeInputsMinMax ( ) ;
182
184
}
183
185
}
184
186
@@ -190,6 +192,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
190
192
connectedCallback ( ) {
191
193
this . _numberInputs = Array . from ( this . _getDomElements ( ".inputs-wrapper input" ) ) ;
192
194
this . _rangeInputs = Array . from ( this . _getDomElements ( ".range-input input" ) ) ;
195
+ this . ready ( ) ;
193
196
}
194
197
195
198
disconnectedCallback ( ) { }
@@ -224,10 +227,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
224
227
}
225
228
} else {
226
229
// Update input values and range progress
227
- this . _numberInputs [ 0 ] . value = minVal . toString ( ) ;
228
- this . _numberInputs [ 1 ] . value = maxVal . toString ( ) ;
229
- this . _updateSliderPosition ( minVal , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
230
- this . _updateSliderPosition ( maxVal , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
230
+ this . valueMin = minVal . toString ( ) ;
231
+ this . valueMax = maxVal . toString ( ) ;
231
232
}
232
233
} ) ;
233
234
@@ -240,10 +241,9 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
240
241
} ) ;
241
242
}
242
243
243
- this . _ready = true ;
244
-
245
244
this . _updateInputValues ( ) ;
246
- this . _updateRangeInputsMinMaxAndValue ( ) ;
245
+ this . _updateRangeInputsMinMax ( ) ;
246
+ this . _updateRangeInputsValues ( ) ;
247
247
this . _updateSliderPosition ( parseInt ( this . valueMin ) , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
248
248
this . _updateSliderPosition ( parseInt ( this . valueMax ) , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
249
249
}
@@ -253,11 +253,14 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
253
253
this . _numberInputs [ 1 ] . value = this . valueMax . toString ( ) ;
254
254
}
255
255
256
- private _updateRangeInputsMinMaxAndValue ( ) {
256
+ private _updateRangeInputsMinMax ( ) {
257
257
this . _rangeInputs . forEach ( rangeInput => {
258
258
rangeInput . min = this . min . toString ( ) ;
259
259
rangeInput . max = this . max . toString ( ) ;
260
260
} ) ;
261
+ }
262
+
263
+ private _updateRangeInputsValues ( ) {
261
264
this . _rangeInputs [ 0 ] . value = this . valueMin . toString ( ) ;
262
265
this . _rangeInputs [ 1 ] . value = this . valueMax . toString ( ) ;
263
266
}
@@ -319,26 +322,6 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
319
322
rangevalue . style . right = `${ 100 - ( relativeValue / range ) * 100 } %` ;
320
323
}
321
324
}
322
-
323
- private _valueMinAttributeChanged ( ) {
324
- if ( ! this . _ready ) return ;
325
- this . _handleInputChange ( { target : this . _numberInputs [ 0 ] } as unknown as Event ) ;
326
- }
327
-
328
- private _valueMaxAttributeChanged ( ) {
329
- if ( ! this . _ready ) return ;
330
- this . _handleInputChange ( { target : this . _numberInputs [ 1 ] } as unknown as Event ) ;
331
- }
332
-
333
- private _minAttributeChanged ( ) {
334
- if ( ! this . _ready ) return ;
335
- this . _updateRangeInputsMinMaxAndValue ( ) ;
336
- }
337
-
338
- private _maxAttributeChanged ( ) {
339
- if ( ! this . _ready ) return ;
340
- this . _updateRangeInputsMinMaxAndValue ( ) ;
341
- }
342
325
}
343
326
344
327
customElements . define ( SliderWebcomponent . is , SliderWebcomponent ) ;
0 commit comments