Skip to content

Commit

Permalink
next: fix select focus on FF/Safari (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Oct 5, 2024
1 parent 7ad3d75 commit e1c644c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-pianos-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: Select trigger refocus in firefox/safari
6 changes: 3 additions & 3 deletions packages/bits-ui/src/lib/bits/select/select.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This logic is adapted from Radix UI's Select component.
* This logic is adapted from Radix UI Select component.
* https://github.com/radix-ui/primitives/blob/main/packages/react/select/src/Select.tsx
* Credit to the Radix UI team for the original implementation.
*/
Expand Down Expand Up @@ -28,7 +28,6 @@ import { afterTick } from "$lib/internal/after-tick.js";
import { clamp } from "$lib/internal/clamp.js";
import { noop } from "$lib/internal/callbacks.js";
import { addEventListener } from "$lib/internal/events.js";
import { sleep } from "$lib/internal/sleep.js";
import type { WithRefProps } from "$lib/internal/types.js";
import { afterSleep } from "$lib/internal/after-sleep.js";

Expand Down Expand Up @@ -128,7 +127,8 @@ export class SelectRootState {
focusTriggerNode = (preventScroll: boolean = true) => {
const node = this.triggerNode;
if (!node) return;
afterSleep(1, () => {
// this needs to be 10 otherwise Firefox doesn't focus the correct node
afterSleep(10, () => {
node.focus({ preventScroll });
});
};
Expand Down

0 comments on commit e1c644c

Please sign in to comment.