Skip to content

Commit

Permalink
Fix scrolling away when opening menu (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Jun 20, 2024
1 parent 1013e24 commit 47f4685
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-paws-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-ux": patch
---

Fix scrolling away when opening menu
4 changes: 2 additions & 2 deletions packages/svelte-ux/src/lib/actions/focus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tick } from 'svelte';
import type { ActionReturn } from 'svelte/action';
import { delay } from '$lib/utils/promise.js';

export function focusMove(
node: HTMLElement,
Expand All @@ -14,7 +14,7 @@ export function focusMove(
// Set `tabIndex` to `-1` which makes any element (ex. div) focusable programmaitcally (and mouse), but not via keyboard navigation - https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
node.tabIndex = -1;
// Appear to need to wait for tabIndex to update before applying focus
tick().then(() => {
delay(0).then(() => {
node.focus();
});

Expand Down

0 comments on commit 47f4685

Please sign in to comment.