From 3722e0ad91d4ad89b009d717b2dc9ab19803a56a Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Mon, 19 Dec 2022 18:17:41 -0500 Subject: [PATCH] focus after open --- src/components/select/select.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 612d90a26..5a4e7c3a8 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -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; } });