diff options
| author | Pierre-Denis Vanduynslager <[email protected]> | 2017-01-21 07:17:34 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2017-10-27 19:19:55 +0300 |
| commit | 6fe72c6de8c9289d1bcd86e0b2cc231789d1aaf4 (patch) | |
| tree | 0b7f4c2b7bb4df5a73a71aa93e59ff8eae16676a /js/src | |
| parent | d51a6c8db31623ce265610c738ad55ad22b70dc9 (diff) | |
| download | bootstrap-6fe72c6de8c9289d1bcd86e0b2cc231789d1aaf4.tar.xz bootstrap-6fe72c6de8c9289d1bcd86e0b2cc231789d1aaf4.zip | |
Dropdown handle keydown on input and textarea.
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/dropdown.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js index e3331ac18..85899d6fc 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -62,6 +62,11 @@ const Dropdown = (($) => { const Selector = { DATA_TOGGLE : '[data-toggle="dropdown"]', FORM_CHILD : '.dropdown form', +<<<<<<< HEAD +======= + ROLE_MENU : '[role="menu"]', + ROLE_LISTBOX : '[role="listbox"]', +>>>>>>> Dropdown handle keydown on input and textarea MENU : '.dropdown-menu', NAVBAR_NAV : '.navbar-nav', VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)' @@ -357,8 +362,17 @@ const Dropdown = (($) => { } static _dataApiKeydownHandler(event) { - if (!REGEXP_KEYDOWN.test(event.which) || /button/i.test(event.target.tagName) && event.which === SPACE_KEYCODE || - /input|textarea/i.test(event.target.tagName)) { + // If not input/textarea: + // - And not a key in REGEXP_KEYDOWN => not a dropdown command + // If input/textarea: + // - If space key => not a dropdown command + // - If key is other than excape + // - If key is not up or down => not a dropdown command + // - If trigger inside the menu => not a dropdown command + if (/input|textarea/i.test(event.target.tagName) ? + event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE && + (event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE || + $(event.target).closest(Selector.MENU).length) : !REGEXP_KEYDOWN.test(event.which)) { return } @@ -418,6 +432,7 @@ const Dropdown = (($) => { $(document) .on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler) +<<<<<<< HEAD .on(Event.KEYDOWN_DATA_API, Selector.MENU, Dropdown._dataApiKeydownHandler) .on(`${Event.CLICK_DATA_API} ${Event.KEYUP_DATA_API}`, Dropdown._clearMenus) .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { @@ -425,6 +440,13 @@ const Dropdown = (($) => { event.stopPropagation() Dropdown._jQueryInterface.call($(this), 'toggle') }) +======= + .on(Event.KEYDOWN_DATA_API, Selector.ROLE_MENU, Dropdown._dataApiKeydownHandler) + .on(Event.KEYDOWN_DATA_API, Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler) + .on(Event.KEYDOWN_DATA_API, Selector.MENU, Dropdown._dataApiKeydownHandler) + .on(`${Event.CLICK_DATA_API} ${Event.FOCUSIN_DATA_API}`, Dropdown._clearMenus) + .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, Dropdown.prototype.toggle) +>>>>>>> Dropdown handle keydown on input and textarea .on(Event.CLICK_DATA_API, Selector.FORM_CHILD, (e) => { e.stopPropagation() }) |
