mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Fixing radioButton checked status (#13974)
* Fixing radioButton checked status * Fixed all kinds of event bugs in radio buttons * removing uneeded checks * Fixing the logic for radiobutton onChange event generation for all possible scenarios. * Made small changes in radioButton logic.
This commit is contained in:
@@ -38,17 +38,14 @@ export class RadioButton extends Widget {
|
|||||||
this.checked = opts.checked || false;
|
this.checked = opts.checked || false;
|
||||||
this.onclick(this.inputElement, () => {
|
this.onclick(this.inputElement, () => {
|
||||||
this._onClicked.fire();
|
this._onClicked.fire();
|
||||||
if (this.name) {
|
this.checked = true;
|
||||||
const buttonGroup = document.getElementsByName(this.name);
|
|
||||||
buttonGroup.forEach((button) => {
|
|
||||||
const event = document.createEvent('HTMLEvents');
|
|
||||||
event.initEvent('change', true, true);
|
|
||||||
button.dispatchEvent(event);
|
|
||||||
});
|
});
|
||||||
|
this.inputElement.addEventListener('change', () => {
|
||||||
|
if (this._internalCheckedStateTracker !== this.inputElement.checked) {
|
||||||
|
this._internalCheckedStateTracker = this.inputElement.checked;
|
||||||
|
this._onChangedCheckedState.fire(this._internalCheckedStateTracker);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.inputElement.addEventListener('change', () => this.checked = this.inputElement.checked);
|
|
||||||
|
|
||||||
container.appendChild(this.inputElement);
|
container.appendChild(this.inputElement);
|
||||||
container.appendChild(this._label);
|
container.appendChild(this._label);
|
||||||
}
|
}
|
||||||
@@ -74,10 +71,18 @@ export class RadioButton extends Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public set checked(val: boolean) {
|
public set checked(val: boolean) {
|
||||||
if (this.inputElement.checked !== this._internalCheckedStateTracker) {
|
if (val !== this._internalCheckedStateTracker) {
|
||||||
this.inputElement.checked = val;
|
this.inputElement.checked = val;
|
||||||
this._internalCheckedStateTracker = val;
|
const event = document.createEvent('HTMLEvents');
|
||||||
this._onChangedCheckedState.fire(this.checked);
|
event.initEvent('change', true, true);
|
||||||
|
if (this.name) {
|
||||||
|
const buttonGroup = document.getElementsByName(this.name);
|
||||||
|
buttonGroup.forEach((button) => {
|
||||||
|
button.dispatchEvent(event);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.inputElement.dispatchEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user