33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import { BaseItem } from './base-item';
|
|
export class CheckboxItem extends BaseItem {
|
|
constructor(id, title) {
|
|
super(id, title);
|
|
}
|
|
getDOMNode() {
|
|
this.container = document.createElement('div');
|
|
this.label = document.createElement('label');
|
|
this.label.setAttribute('for', `chkbx_${this.id}`);
|
|
this.label.textContent = this.title;
|
|
this.checkboxElement = document.createElement('input');
|
|
this.checkboxElement.setAttribute('type', 'checkbox');
|
|
this.checkboxElement.setAttribute('id', `chkbx_${this.id}`);
|
|
this.checkboxElement.addEventListener('focus', this.onFocus.bind(this));
|
|
this.checkboxElement.addEventListener('change', this.onChange.bind(this));
|
|
this.container.appendChild(this.label);
|
|
this.container.appendChild(this.checkboxElement);
|
|
return this.container;
|
|
}
|
|
getContents() {
|
|
return this.checkboxElement.checked;
|
|
}
|
|
onChange(event) {
|
|
this.emit('update', {
|
|
type: 'checkbox',
|
|
value: this.checkboxElement.checked
|
|
});
|
|
}
|
|
focus() {
|
|
this.checkboxElement.focus();
|
|
}
|
|
}
|