Skip to content

Commit

Permalink
MDL-84324 core: Fix Bootstrap dropdown key listeners
Browse files Browse the repository at this point in the history
Bootstrap EventHandler is managing the keydown event at document
level in the capture phase. That is conflicting with dropdown elements
with form autocomplete inputs inside, because when suggestions panel is
open, pressing the "Esc" key will close the whole dropdown.
This commit fixes that behaviour by realocating the Bootsrap dropdown
event listener to the body instead of the document.
  • Loading branch information
roland04 committed Feb 13, 2025
1 parent 5052af4 commit 67bdc82
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/amd/build/form-autocomplete.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/amd/build/form-autocomplete.min.js.map

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion lib/amd/src/form-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ define([
'core/aria',
'core_form/changechecker',
'core/popper2',
'theme_boost/bootstrap/dom/event-handler',
], function(
$,
log,
Expand All @@ -40,7 +41,8 @@ define([
LoadingIcon,
Aria,
FormChangeChecker,
Popper
Popper,
EventHandler,
) {
// Private functions and variables.
/** @var {Object} KEYS - List of keycode constants. */
Expand Down Expand Up @@ -1083,6 +1085,16 @@ define([
});
}
}

// Add a Bootstrap keydown handler to close the suggestions list preventing the hole Dropdown close.
EventHandler.on(document, 'keydown.bs.dropdown.data-api', '.dropdown-menu', (event) => {
const pendingPromise = addPendingJSPromise('addNavigation-' + state.inputId + '-' + event.key);
if (event.key === "Escape" && inputElement.attr('aria-expanded') === "true") {
event.stopImmediatePropagation();
return pendingPromise.resolve(closeSuggestions(state));
}
return pendingPromise.resolve();
});
};

/**
Expand Down
2 changes: 1 addition & 1 deletion theme/boost/amd/build/aria.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion theme/boost/amd/build/aria.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions theme/boost/amd/build/loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 67bdc82

Please sign in to comment.