Default checkbox aria label to label (#8367)

This commit is contained in:
Charles Gagnon
2019-11-18 10:24:27 -08:00
committed by GitHub
parent bafd9fd437
commit 66048f1d63

View File

@@ -30,15 +30,15 @@ export class Checkbox extends Widget {
private _onChange = new Emitter<boolean>(); private _onChange = new Emitter<boolean>();
public readonly onChange: Event<boolean> = this._onChange.event; public readonly onChange: Event<boolean> = this._onChange.event;
constructor(container: HTMLElement, opts: ICheckboxOptions) { constructor(container: HTMLElement, private _opts: ICheckboxOptions) {
super(); super();
this._el = document.createElement('input'); this._el = document.createElement('input');
this._el.type = 'checkbox'; this._el.type = 'checkbox';
this._el.style.verticalAlign = 'middle'; this._el.style.verticalAlign = 'middle';
if (opts.ariaLabel) { if (_opts.ariaLabel) {
this._el.setAttribute('aria-label', opts.ariaLabel); this._el.setAttribute('aria-label', _opts.ariaLabel);
} }
this.onchange(this._el, e => { this.onchange(this._el, e => {
@@ -55,12 +55,12 @@ export class Checkbox extends Widget {
this._label = document.createElement('span'); this._label = document.createElement('span');
this._label.style.verticalAlign = 'middle'; this._label.style.verticalAlign = 'middle';
this.label = opts.label; this.label = _opts.label;
this.enabled = opts.enabled || true; this.enabled = _opts.enabled || true;
this.checked = opts.checked || false; this.checked = _opts.checked || false;
if (opts.onChange) { if (_opts.onChange) {
this.onChange(opts.onChange); this.onChange(_opts.onChange);
} }
container.appendChild(this._el); container.appendChild(this._el);
@@ -69,6 +69,10 @@ export class Checkbox extends Widget {
public set label(val: string) { public set label(val: string) {
this._label.innerText = val; this._label.innerText = val;
// Default the aria label to the label if one wasn't specifically set by the user
if (!this._opts.ariaLabel) {
this._el.setAttribute('aria-label', val);
}
} }
public set enabled(val: boolean) { public set enabled(val: boolean) {