Skip to content

Commit

Permalink
fix: Update attributes and prevent infinite loops
Browse files Browse the repository at this point in the history
- Implement `_suppressAttributeChange` flag to avoid recursive attribute change callbacks.
  • Loading branch information
7evenk committed Jun 23, 2024
1 parent 1d2f344 commit 77c8221
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/slider/SliderWebcomponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,46 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
private _rangeInputs: HTMLInputElement[];
private _ready: Boolean = false;
private _valuesGap: number = 1;
private _suppressAttributeChange: boolean = false;

public get valueMin() {
return this.getAttribute('value-min');
}
public set valueMin(value) {
this._suppressAttributeChange = true;
this.setAttribute('value-min', value.toString());
this._suppressAttributeChange = false;
}

public get valueMax() {
return this.getAttribute('value-max');
}
public set valueMax(value) {
this._suppressAttributeChange = true;
this.setAttribute('value-max', value.toString());
this._suppressAttributeChange = false;
}

public get min() {
return this.getAttribute('min');
}
public set min(value) {
this._suppressAttributeChange = true;
this.setAttribute('min', value.toString());
this._suppressAttributeChange = false;
}

public get max() {
return this.getAttribute('max');
}
public set max(value) {
this._suppressAttributeChange = true;
this.setAttribute('max', value.toString());
this._suppressAttributeChange = false;
}

attributeChangedCallback(name: string, oldValue: string, newValue: string) {
if (this._suppressAttributeChange) return;
if (name == "value-min") {
this._valueMinAttributeChanged();
}
Expand Down Expand Up @@ -230,7 +240,6 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
});
}


this._ready = true;

this._updateInputValues();
Expand Down Expand Up @@ -294,6 +303,8 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
this._updateSliderPosition(maxp, value2, false);
}
}
this.valueMin = this._rangeInputs[0].value;
this.valueMax = this._rangeInputs[1].value;
}

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

0 comments on commit 77c8221

Please sign in to comment.