MDL-75669 theme_boost: Fix formautocomplete inside dropdowns

Fix problem where having a dropdown with a form autocomplete inside and
pressing Escape key will close the hole dropdown instead only the autocomplete
suggestions.
This commit is contained in:
Mikel Martín
2025-02-17 08:13:47 +01:00
parent ad37483f47
commit 4746042423
3 changed files with 19 additions and 2 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+17
View File
@@ -227,6 +227,23 @@ const dropdownFix = () => {
});
}
});
// Prevent closing the dropdown when the autocomplete suggestions are visible.
document.addEventListener('hide.bs.dropdown', (e) => {
const dropdown = e.target.closest('.dropdown');
if (!dropdown) {
return;
}
const autocompleteSuggestions = document.querySelector('.form-autocomplete-suggestions:not([aria-hidden="true"])');
if (autocompleteSuggestions) {
// Dropdown should not be hidden while the autocomplete suggestions are visible inside.
e.preventDefault();
// Return the focus to the autocomplete input.
const autocompleteElement = autocompleteSuggestions.closest('[data-fieldtype="autocomplete"]');
const autocompleteInput = autocompleteElement.querySelector('.form-autocomplete-input input');
setTimeout(()=> autocompleteInput.focus(), 1000);
}
});
};
/**