Skip to content

Commit e665407

Browse files
committed
Use a Promise instead of async/ await in TrapFocus onMount
Currently async/ await is used in TrapFocus and ends up in the transpiled files in dist. Avoid using async/ await which requires more complex transformation and isn't supported by tools like buble.
1 parent d1ac315 commit e665407

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/components/TrapFocus.svelte

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
let lastTabbableChild;
1212
let returnFocusElem;
1313
14-
onMount(async () => {
14+
onMount(() => {
1515
returnFocusElem = returnFocusElement || document.activeElement;
1616
tabbableChildren = [...ref.querySelectorAll("*")].filter((node) => node.tabIndex >= 0);
1717
firstTabbableChild = tabbableChildren[0];
1818
lastTabbableChild = tabbableChildren[tabbableChildren.length - 1];
1919
2020
// Wait for children to mount before trying to focus `initialFocusElement`
21-
await tick();
21+
tick().then(() => {
22+
if (initialFocusElement) {
23+
initialFocusElement.focus();
24+
} else {
25+
const initialFocusElem =
26+
ref.querySelector("[autofocus]") ||
27+
firstTabbableChild ||
28+
ref.querySelector("[data-svelte-dialog-content]");
2229
23-
if (initialFocusElement) {
24-
initialFocusElement.focus();
25-
} else {
26-
const initialFocusElem =
27-
ref.querySelector("[autofocus]") ||
28-
firstTabbableChild ||
29-
ref.querySelector("[data-svelte-dialog-content]");
30-
31-
initialFocusElem.focus();
32-
}
30+
initialFocusElem.focus();
31+
}
32+
});
3333
});
3434
3535
onDestroy(() => {

0 commit comments

Comments
 (0)