dropdown_list_widget: Properly bind focus event to input field.

Previously, the focus event was triggering on a hidden
dropdown input field, which caused it to not gain focus when
clicked on dropdown button.

This is so because focus events cannot be triggered to
hidden elements or elements that aren't visible in DOM.

Added a fix by explicilty triggering the focus event to
dropdown input field only if the input field is visible in the DOM.
This commit is contained in:
aryanshridhar
2021-03-30 22:54:52 +05:30
committed by Tim Abbott
parent a3baf90d3a
commit 2c50c67d07

View File

@@ -119,7 +119,13 @@ export const DropdownListWidget = function ({
// On opening a Bootstrap Dropdown, the parent element receives focus.
// Here, we want our search input to have focus instead.
e.preventDefault();
search_input.trigger("focus");
// This function gets called twice when focusing the
// dropdown, and only in the second call is the input
// field visible in the DOM; so the following visibility
// check ensures we wait for the second call to focus.
if (dropdown_list_body.is(":visible")) {
search_input.trigger("focus");
}
});
search_input.on("keydown", (e) => {