1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-06-13 00:41:59 +03:00

Updated another set of components

This commit is contained in:
Dan Brown
2022-11-15 12:44:57 +00:00
parent 4310d34135
commit b37e84dc10
17 changed files with 119 additions and 143 deletions

View File

@ -1,18 +1,19 @@
import {Component} from "./component";
class CustomCheckbox {
export class CustomCheckbox extends Component {
constructor(elem) {
this.elem = elem;
this.checkbox = elem.querySelector('input[type=checkbox]');
this.display = elem.querySelector('[role="checkbox"]');
setup() {
this.container = this.$el;
this.checkbox = this.container.querySelector('input[type=checkbox]');
this.display = this.container.querySelector('[role="checkbox"]');
this.checkbox.addEventListener('change', this.stateChange.bind(this));
this.elem.addEventListener('keydown', this.onKeyDown.bind(this));
this.container.addEventListener('keydown', this.onKeyDown.bind(this));
}
onKeyDown(event) {
const isEnterOrPress = event.keyCode === 32 || event.keyCode === 13;
if (isEnterOrPress) {
const isEnterOrSpace = event.key === ' ' || event.key === 'Enter';
if (isEnterOrSpace) {
event.preventDefault();
this.toggle();
}
@ -29,6 +30,4 @@ class CustomCheckbox {
this.display.setAttribute('aria-checked', checked);
}
}
export default CustomCheckbox;
}