@@ -81,6 +81,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
81
81
private _rangeInputs : HTMLInputElement [ ] ;
82
82
private _valuesGap : number = 1 ;
83
83
private _suppressAttributeChange : boolean = false ;
84
+ private _currentMinVal : number ;
85
+ private _currentMaxVal : number ;
84
86
85
87
attributeChangedCallback ( name : string , oldValue : string , newValue : string ) {
86
88
if ( this . _suppressAttributeChange ) return ;
@@ -99,15 +101,17 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
99
101
this . _restoreCachedInititalValues ( ) ;
100
102
}
101
103
102
- connectedCallback ( ) {
103
- this . _rangeInputs = Array . from ( this . _getDomElements ( ".range-input input" ) ) ;
104
- }
105
-
106
104
disconnectedCallback ( ) { }
107
105
108
106
ready ( ) {
107
+ this . _rangeInputs = Array . from ( this . _getDomElements ( ".range-input input" ) ) ;
108
+
109
109
this . _parseAttributesToProperties ( ) ;
110
110
111
+ // Initialize current values
112
+ this . _currentMinVal = parseInt ( this . getAttribute ( 'value-min' ) ) ;
113
+ this . _currentMaxVal = parseInt ( this . getAttribute ( 'value-max' ) ) ;
114
+
111
115
// Add event listeners to range input elements
112
116
for ( let i = 0 ; i < this . _rangeInputs . length ; i ++ ) {
113
117
this . _rangeInputs [ i ] . addEventListener ( "input" , e => {
@@ -121,8 +125,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
121
125
122
126
this . _updateRangeInputsMinMax ( ) ;
123
127
this . _updateRangeInputsValues ( ) ;
124
- this . _updateSliderPosition ( parseInt ( this . getAttribute ( 'value-min' ) ) , parseInt ( this . getAttribute ( 'max' ) ) , true ) ;
125
- this . _updateSliderPosition ( parseInt ( this . getAttribute ( 'value-max' ) ) , parseInt ( this . getAttribute ( 'max' ) ) , false ) ;
128
+ this . _updateSliderPosition ( this . _currentMinVal , parseInt ( this . getAttribute ( 'max' ) ) , true ) ;
129
+ this . _updateSliderPosition ( this . _currentMaxVal , parseInt ( this . getAttribute ( 'max' ) ) , false ) ;
126
130
}
127
131
128
132
private _validateValues ( changedAttr : string , newValue : string ) {
@@ -141,8 +145,12 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
141
145
const oldValueMax = parseInt ( this . getAttribute ( 'value-max' ) ) ;
142
146
143
147
this . _suppressAttributeChange = true ;
144
- this . setAttribute ( 'value-min' , valueMin . toString ( ) ) ;
145
- this . setAttribute ( 'value-max' , valueMax . toString ( ) ) ;
148
+ if ( valueMin !== oldValueMin ) {
149
+ this . setAttribute ( 'value-min' , valueMin . toString ( ) ) ;
150
+ }
151
+ if ( valueMax !== oldValueMax ) {
152
+ this . setAttribute ( 'value-max' , valueMax . toString ( ) ) ;
153
+ }
146
154
this . _suppressAttributeChange = false ;
147
155
148
156
this . _updateRangeInputsValues ( ) ;
@@ -157,15 +165,19 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
157
165
}
158
166
159
167
private _updateRangeInputsMinMax ( ) {
160
- this . _rangeInputs . forEach ( rangeInput => {
161
- rangeInput . min = this . getAttribute ( 'min' ) ;
162
- rangeInput . max = this . getAttribute ( 'max' ) ;
163
- } ) ;
168
+ if ( this . _rangeInputs ) {
169
+ this . _rangeInputs . forEach ( rangeInput => {
170
+ rangeInput . min = this . getAttribute ( 'min' ) ;
171
+ rangeInput . max = this . getAttribute ( 'max' ) ;
172
+ } ) ;
173
+ }
164
174
}
165
175
166
176
private _updateRangeInputsValues ( ) {
167
- this . _rangeInputs [ 0 ] . value = this . getAttribute ( 'value-min' ) ;
168
- this . _rangeInputs [ 1 ] . value = this . getAttribute ( 'value-max' ) ;
177
+ if ( this . _rangeInputs ) {
178
+ this . _rangeInputs [ 0 ] . value = this . getAttribute ( 'value-min' ) ;
179
+ this . _rangeInputs [ 1 ] . value = this . getAttribute ( 'value-max' ) ;
180
+ }
169
181
}
170
182
171
183
private _handleRangeInput ( e : Event ) {
@@ -185,8 +197,12 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
185
197
} else {
186
198
// Update input values and range progress
187
199
this . _suppressAttributeChange = true ;
188
- this . setAttribute ( 'value-min' , minVal . toString ( ) ) ;
189
- this . setAttribute ( 'value-max' , maxVal . toString ( ) ) ;
200
+ if ( parseInt ( this . getAttribute ( 'value-min' ) ) !== minVal ) {
201
+ this . setAttribute ( 'value-min' , minVal . toString ( ) ) ;
202
+ }
203
+ if ( parseInt ( this . getAttribute ( 'value-max' ) ) !== maxVal ) {
204
+ this . setAttribute ( 'value-max' , maxVal . toString ( ) ) ;
205
+ }
190
206
this . _suppressAttributeChange = false ;
191
207
this . _updateSliderPosition ( minVal , parseInt ( this . getAttribute ( 'max' ) ) , true ) ;
192
208
this . _updateSliderPosition ( maxVal , parseInt ( this . getAttribute ( 'max' ) ) , false ) ;
@@ -197,21 +213,18 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
197
213
let minVal = parseInt ( this . _rangeInputs [ 0 ] . value ) ;
198
214
let maxVal = parseInt ( this . _rangeInputs [ 1 ] . value ) ;
199
215
200
- // Prevent duplicate event firing
201
- const currentMinVal = parseInt ( this . getAttribute ( 'value-min' ) ) ;
202
- const currentMaxVal = parseInt ( this . getAttribute ( 'value-max' ) ) ;
203
-
204
- this . _suppressAttributeChange = true ;
205
- this . setAttribute ( 'value-min' , minVal . toString ( ) ) ;
206
- this . setAttribute ( 'value-max' , maxVal . toString ( ) ) ;
207
- this . _suppressAttributeChange = false ;
216
+ // Check if values actually changed
217
+ if ( minVal !== this . _currentMinVal || maxVal !== this . _currentMaxVal ) {
218
+ this . _currentMinVal = minVal ;
219
+ this . _currentMaxVal = maxVal ;
208
220
209
221
// Dispatch the appropriate event
210
222
if ( ( e . target as HTMLInputElement ) . className === "min-range" ) {
211
223
this . _dispatchChangeEvent ( 'value-min-changed' , minVal ) ;
212
224
} else {
213
225
this . _dispatchChangeEvent ( 'value-max-changed' , maxVal ) ;
214
226
}
227
+ }
215
228
}
216
229
217
230
private _updateSliderPosition ( value : number , max : number , isMin : boolean ) {
0 commit comments