Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/globals/mixins/focus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2019
* Copyright IBM Corp. 2019, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -21,7 +21,14 @@ const FocusMixin = <T extends Constructor<HTMLElement>>(Base: T) =>
focus() {
// @ts-ignore: Until `delegatesFocus` is added to `ShadowRoot` definition
if (this.shadowRoot!.delegatesFocus) {
super.focus();
const primaryFocusNode =
this.shadowRoot!.querySelector('[data-primary-focus]') || this.querySelector('[data-primary-focus]');

if (primaryFocusNode) {
(primaryFocusNode as HTMLElement).focus();
} else {
super.focus();
}
} else {
const delegateTarget = this.shadowRoot!.querySelector(selectorTabbable) || this.querySelector(selectorTabbable);
if (delegateTarget) {
Expand Down