focus after open

pull/1090/head
Cory LaViska 2022-12-19 18:17:41 -05:00
rodzic f28a0ec743
commit 3722e0ad91
1 zmienionych plików z 6 dodań i 9 usunięć

Wyświetl plik

@ -473,20 +473,17 @@ export default class SlSelect extends ShoelaceElement implements ShoelaceFormCon
this.listbox.hidden = false;
this.popup.active = true;
// Select the correct option
const currentOption = this.getOptionByValue(this.value);
this.setCurrentOption(currentOption);
this.setSelectedOption(currentOption);
// Scroll the selected option into view
requestAnimationFrame(() => {
const selectedOption = this.getSelectedOption();
// Select the appropriate option based on value after the listbox opens
const option = this.getOptionByValue(this.value);
this.setCurrentOption(option);
this.setSelectedOption(option);
if (selectedOption) {
if (option) {
//
// TODO - improve this logic so the selected option is centered in the listbox instead of at the top
//
this.listbox.scrollTop = selectedOption.offsetTop;
this.listbox.scrollTop = option.offsetTop;
}
});