From d6d05121e4af4cd533a0b62e1a01c47ee5bdca26 Mon Sep 17 00:00:00 2001 From: ErikOnBike Date: Fri, 17 Dec 2021 15:15:47 +0100 Subject: [PATCH] Add focus method to SlSelect (#625) --- src/components/select/select.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/select/select.ts b/src/components/select/select.ts index f36aeed32..11c365ab5 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -179,6 +179,12 @@ export default class SlSelect extends LitElement { return Array.isArray(this.value) ? this.value : [this.value]; } + /** Sets focus on the control. */ + focus(options?: FocusOptions) { + const box = this.shadowRoot?.querySelector('.select__control') as HTMLElement; + box.focus(options); + } + handleBlur() { // Don't blur if the control is open. We'll move focus back once it closes. if (!this.isOpen) { @@ -271,8 +277,7 @@ export default class SlSelect extends LitElement { } handleLabelClick() { - const box = this.shadowRoot?.querySelector('.select__control') as HTMLElement; - box.focus(); + this.focus(); } handleMenuSelect(event: CustomEvent) {