Checkboxes: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
Bar | Bar | ||
< | <pre></b-form-checkbox></pre> | ||
Line 16: | Line 16: | ||
< | <pre>private onKeyDownFooCheckbox(e: KeyboardEvent) | ||
{ | { | ||
this.emulateTab( | this.emulateTab( | ||
Line 28: | Line 28: | ||
(this.$refs.bazField as any).$el.select(); | (this.$refs.bazField as any).$el.select(); | ||
}); | }); | ||
}</ | }</pre> | ||
Line 34: | Line 34: | ||
< | <pre>private initializeKeyDownEvents() { | ||
(this.$refs.fooCheckbox as any).$el.parentNode.removeEventListener('keydown', this.onKeyDownFooCheckbox); | (this.$refs.fooCheckbox as any).$el.parentNode.removeEventListener('keydown', this.onKeyDownFooCheckbox); | ||
(this.$refs.fooCheckbox as any).$el.parentNode.addEventListener('keydown', this.onKeyDownFooCheckbox); | (this.$refs.fooCheckbox as any).$el.parentNode.addEventListener('keydown', this.onKeyDownFooCheckbox); | ||
}</ | }</pre> |
Revision as of 14:48, 2 October 2023
Use BoostrapVue's checkbox:
<b-form-checkbox v-model="isBar" >
Bar
</b-form-checkbox>
Confusingly, it can also be <b-checkbox> (src).
Tab navigation. See Tab Key Navigation section. To navigate away from the dropdown, define the keydown event handler:
private onKeyDownFooCheckbox(e: KeyboardEvent) { this.emulateTab( e, () => { (this.$refs.barField as any).$el.focus(); (this.$refs.barField as any).$el.select(); }, () => { (this.$refs.bazField as any).$el.focus(); (this.$refs.bazField as any).$el.select(); }); }
Then add @keydown="onKeyDownFooCheckbox" define a method to set the keydown event listener on the checkbox and call it in mounted() callback:
private initializeKeyDownEvents() { (this.$refs.fooCheckbox as any).$el.parentNode.removeEventListener('keydown', this.onKeyDownFooCheckbox); (this.$refs.fooCheckbox as any).$el.parentNode.addEventListener('keydown', this.onKeyDownFooCheckbox); }