Skip to content

Commit 77c8221

Browse files
committed
fix: Update attributes and prevent infinite loops
- Implement `_suppressAttributeChange` flag to avoid recursive attribute change callbacks.
1 parent 1d2f344 commit 77c8221

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/slider/SliderWebcomponent.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,36 +128,46 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
128128
private _rangeInputs: HTMLInputElement[];
129129
private _ready: Boolean = false;
130130
private _valuesGap: number = 1;
131+
private _suppressAttributeChange: boolean = false;
131132

132133
public get valueMin() {
133134
return this.getAttribute('value-min');
134135
}
135136
public set valueMin(value) {
137+
this._suppressAttributeChange = true;
136138
this.setAttribute('value-min', value.toString());
139+
this._suppressAttributeChange = false;
137140
}
138141

139142
public get valueMax() {
140143
return this.getAttribute('value-max');
141144
}
142145
public set valueMax(value) {
146+
this._suppressAttributeChange = true;
143147
this.setAttribute('value-max', value.toString());
148+
this._suppressAttributeChange = false;
144149
}
145150

146151
public get min() {
147152
return this.getAttribute('min');
148153
}
149154
public set min(value) {
155+
this._suppressAttributeChange = true;
150156
this.setAttribute('min', value.toString());
157+
this._suppressAttributeChange = false;
151158
}
152159

153160
public get max() {
154161
return this.getAttribute('max');
155162
}
156163
public set max(value) {
164+
this._suppressAttributeChange = true;
157165
this.setAttribute('max', value.toString());
166+
this._suppressAttributeChange = false;
158167
}
159168

160169
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
170+
if (this._suppressAttributeChange) return;
161171
if (name == "value-min") {
162172
this._valueMinAttributeChanged();
163173
}
@@ -230,7 +240,6 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
230240
});
231241
}
232242

233-
234243
this._ready = true;
235244

236245
this._updateInputValues();
@@ -294,6 +303,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
294303
this._updateSliderPosition(maxp, value2, false);
295304
}
296305
}
306+
this.valueMin = this._rangeInputs[0].value;
307+
this.valueMax = this._rangeInputs[1].value;
297308
}
298309

299310
private _updateSliderPosition(value: number, max: number, isMin: boolean) {

0 commit comments

Comments
 (0)