-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Description
Code used:
const $select = document.querySelector("select");
window.accessibleAutocomplete.enhanceSelectElement({
selectElement: $select
});Steps to reproduce:
- Enter a value in the autocomplete input
- Select an option
- Notice that the underlying select element is updated
- Select the value in the autocomplete input and delete it
- Click outside the input
- Notice that the underlying select element is still as was selected on step 3
Expected behaviour:
If the input is empty all options are unselected.
This is what I ended up doing to work around this:
const $select = document.querySelector("select");
window.accessibleAutocomplete.enhanceSelectElement({
selectElement: $select,
onConfirm: (query) => {
const $wrapper = document.getElementById($select.id).parentNode;
const $input = $wrapper.querySelector("input");
const inputEmpty = $input.value === "";
const selectOptions = Array.from($select.options);
const requestedOption = selectOptions.filter(option => {
return (option.textContent || option.innerText) === query;
})[0];
if (requestedOption) {
console.log("Selected", requestedOption.value);
requestedOption.selected = true;
} else if (inputEmpty) {
console.log("Reset the select");
selectOptions.forEach(option => (option.selected = false));
}
}
});Metadata
Metadata
Assignees
Labels
No labels