60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
"use strict";
|
|
|
|
// Select-only radio button
|
|
Toolkit.RadioButton = class RadioButton extends Toolkit.CheckBox {
|
|
|
|
// Object constructor
|
|
constructor(application, options) {
|
|
super(application, options);
|
|
options = options || {};
|
|
|
|
// Configure instance fields
|
|
this.group = null;
|
|
|
|
// Configure element
|
|
this.element.setAttribute("role", "radio");
|
|
|
|
// Configure properties
|
|
this.setGroup(options.group || null);
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////// Public Methods //////////////////////////////
|
|
|
|
// Retrieve the enclosing ButtonGroup
|
|
getGroup() {
|
|
return this.group;
|
|
}
|
|
|
|
// Specify whether the component is checked (overrides superclass)
|
|
setChecked(checked, e) {
|
|
checked = !!checked;
|
|
if (e instanceof Event && !checked || checked == this.checked)
|
|
return;
|
|
|
|
this.checked = checked;
|
|
this.element.setAttribute("aria-checked", checked);
|
|
if (this.group != null && e != this.group)
|
|
this.group.setChecked(this);
|
|
|
|
if (e === undefined)
|
|
return;
|
|
for (let listener of this.changeListeners)
|
|
listener(e);
|
|
}
|
|
|
|
// Specify the enclosing ButtonGroup
|
|
setGroup(group) {
|
|
group = group || null;
|
|
if (group == this.group)
|
|
return;
|
|
if (this.group != null)
|
|
this.group.remove(this);
|
|
this.group = group;
|
|
if (group != null)
|
|
group.add(this);
|
|
}
|
|
|
|
};
|