X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b27a5c7fb876c74c676eb9114383c25d82eb87fb..refs/heads/captcha_example:/resources/assets/js/components/dropdown.js diff --git a/resources/assets/js/components/dropdown.js b/resources/assets/js/components/dropdown.js index e2bb21b0c..4de1e239b 100644 --- a/resources/assets/js/components/dropdown.js +++ b/resources/assets/js/components/dropdown.js @@ -112,15 +112,14 @@ class DropDown { onSelect(this.toggle, event => { event.stopPropagation(); - console.log('cat', event); this.show(event); if (event instanceof KeyboardEvent) { this.focusNext(); } }); - // Arrow navigation - this.container.addEventListener('keydown', event => { + // Keyboard navigation + const keyboardNavigation = event => { if (event.key === 'ArrowDown' || event.key === 'ArrowRight') { this.focusNext(); event.preventDefault(); @@ -129,9 +128,14 @@ class DropDown { event.preventDefault(); } else if (event.key === 'Escape') { this.hide(); + this.toggle.focus(); event.stopPropagation(); } - }); + }; + this.container.addEventListener('keydown', keyboardNavigation); + if (this.moveMenu) { + this.menu.addEventListener('keydown', keyboardNavigation); + } // Hide menu on enter press or escape this.menu.addEventListener('keydown ', event => {