Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: fix select focus on FF/Safari #735

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
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
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