X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/feab756b9f1e6b47d9877cd746a827fb9c604fe5..refs/pull/3138/head:/resources/js/components/dropdown.js diff --git a/resources/js/components/dropdown.js b/resources/js/components/dropdown.js index 367c956ce..f761ecf01 100644 --- a/resources/js/components/dropdown.js +++ b/resources/js/components/dropdown.js @@ -3,18 +3,22 @@ import {onSelect} from "../services/dom"; /** * Dropdown * Provides some simple logic to create simple dropdown menus. + * @extends {Component} */ class DropDown { - constructor(elem) { - this.container = elem; - this.menu = elem.querySelector('.dropdown-menu, [dropdown-menu]'); - this.moveMenu = elem.hasAttribute('dropdown-move-menu'); - this.toggle = elem.querySelector('[dropdown-toggle]'); + setup() { + this.container = this.$el; + this.menu = this.$refs.menu; + this.toggle = this.$refs.toggle; + this.moveMenu = this.$opts.moveMenu; + this.bubbleEscapes = this.$opts.bubbleEscapes === 'true'; + this.direction = (document.dir === 'rtl') ? 'right' : 'left'; this.body = document.body; this.showing = false; this.setupListeners(); + this.hide = this.hide.bind(this); } show(event = null) { @@ -134,7 +138,9 @@ class DropDown { } else if (event.key === 'Escape') { this.hide(); this.toggle.focus(); - event.stopPropagation(); + if (!this.bubbleEscapes) { + event.stopPropagation(); + } } }; this.container.addEventListener('keydown', keyboardNavigation);