@@ -158,18 +158,18 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
158
158
}
159
159
160
160
attributeChangedCallback ( name : string , oldValue : string , newValue : string ) {
161
- if ( name == "value-min" ) {
162
- this . _valueMinAttributeChanged ( ) ;
163
- }
164
- if ( name === "value-max" ) {
165
- this . _valueMaxAttributeChanged ( ) ;
166
- }
167
- if ( name == "min" ) {
168
- this . _minAttributeChanged ( ) ;
169
- }
170
- if ( name === "max" ) {
171
- this . _maxAttributeChanged ( ) ;
172
- }
161
+ if ( name == "value-min" ) {
162
+ this . _valueMinAttributeChanged ( ) ;
163
+ }
164
+ if ( name === "value-max" ) {
165
+ this . _valueMaxAttributeChanged ( ) ;
166
+ }
167
+ if ( name == "min" ) {
168
+ this . _minAttributeChanged ( ) ;
169
+ }
170
+ if ( name === "max" ) {
171
+ this . _maxAttributeChanged ( ) ;
172
+ }
173
173
}
174
174
175
175
constructor ( ) {
@@ -182,7 +182,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
182
182
this . _rangeInputs = Array . from ( this . _getDomElements ( ".range-input input" ) ) ;
183
183
}
184
184
185
- disconnectedCallback ( ) { }
185
+ disconnectedCallback ( ) { }
186
186
187
187
ready ( ) {
188
188
this . _parseAttributesToProperties ( ) ;
@@ -196,36 +196,41 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
196
196
} ) ;
197
197
}
198
198
199
- // Add event listeners to range input elements
199
+ // Add event listeners to range input elements
200
200
for ( let i = 0 ; i < this . _rangeInputs . length ; i ++ ) {
201
- this . _rangeInputs [ i ] . addEventListener ( "change " , e => {
201
+ this . _rangeInputs [ i ] . addEventListener ( "input " , e => {
202
202
let minVal = parseInt ( this . _rangeInputs [ 0 ] . value ) ;
203
203
let maxVal = parseInt ( this . _rangeInputs [ 1 ] . value ) ;
204
204
205
205
let diff = maxVal - minVal ;
206
206
207
- // Check if the values gap is exceeded
207
+ // Check if the values gap is exceeded
208
208
if ( diff < this . _valuesGap ) {
209
-
210
- // Check if the input is the min range input
209
+ // Check if the input is the min range input
211
210
if ( ( e . target as HTMLInputElement ) . className === "min-range" ) {
212
211
this . _rangeInputs [ 0 ] . value = ( maxVal - this . _valuesGap ) . toString ( ) ;
213
212
} else {
214
213
this . _rangeInputs [ 1 ] . value = ( minVal + this . _valuesGap ) . toString ( ) ;
215
214
}
216
215
} else {
217
-
218
- // Update input values and range progress
216
+ // Update input values and range progress
219
217
this . _numberInputs [ 0 ] . value = minVal . toString ( ) ;
220
218
this . _numberInputs [ 1 ] . value = maxVal . toString ( ) ;
221
- this . valueMin = minVal . toString ( ) ;
222
- this . valueMax = maxVal . toString ( ) ;
223
- this . _updateSliderPosition ( parseInt ( this . valueMin ) , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
224
- this . _updateSliderPosition ( parseInt ( this . valueMax ) , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
219
+ this . _updateSliderPosition ( minVal , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
220
+ this . _updateSliderPosition ( maxVal , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
225
221
}
226
222
} ) ;
223
+
224
+ this . _rangeInputs [ i ] . addEventListener ( "change" , e => {
225
+ let minVal = parseInt ( this . _rangeInputs [ 0 ] . value ) ;
226
+ let maxVal = parseInt ( this . _rangeInputs [ 1 ] . value ) ;
227
+
228
+ this . valueMin = minVal . toString ( ) ;
229
+ this . valueMax = maxVal . toString ( ) ;
230
+ } ) ;
227
231
}
228
232
233
+
229
234
this . _ready = true ;
230
235
231
236
this . _updateInputValues ( ) ;
@@ -294,15 +299,15 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
294
299
private _updateSliderPosition ( value : number , max : number , isMin : boolean ) {
295
300
const rangevalue : HTMLDivElement = this . _getDomElement ( "slider" ) ;
296
301
const range = parseInt ( this . max ) - parseInt ( this . min ) ; // Calculate the total range
297
-
302
+
298
303
if ( isMin ) {
299
304
const relativeValue = value - parseInt ( this . min ) ; // Calculate the relative value within the range
300
305
rangevalue . style . left = `${ ( relativeValue / range ) * 100 } %` ;
301
306
} else {
302
307
const relativeValue = value - parseInt ( this . min ) ; // Calculate the relative value within the range
303
308
rangevalue . style . right = `${ 100 - ( relativeValue / range ) * 100 } %` ;
304
309
}
305
- }
310
+ }
306
311
307
312
private _valueMinAttributeChanged ( ) {
308
313
if ( ! this . _ready ) return ;
0 commit comments