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

[Select] Retain highlight while transitioning out #972

Merged
merged 10 commits into from
Dec 11, 2024
Merged
Prev Previous commit
Next Next commit
Move workaround
  • Loading branch information
atomiks committed Dec 9, 2024
commit 94343496b7d8e2d6751f3ab46a431b423d3a42a4
13 changes: 13 additions & 0 deletions packages/react/src/select/root/useSelectRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export function useSelectRoot<T>(params: useSelectRoot.Parameters<T>): useSelect
const setOpen = useEventCallback((nextOpen: boolean, event?: Event) => {
params.onOpenChange?.(nextOpen, event);
setOpenUnwrapped(nextOpen);

// Workaround `enableFocusInside` in Floating UI setting `tabindex=0` of a non-highlighted
// option upon close when tabbing out due to `keepMounted=true`:
// https://github.com/floating-ui/floating-ui/pull/3004/files#diff-962a7439cdeb09ea98d4b622a45d517bce07ad8c3f866e089bda05f4b0bbd875R194-R199
// This otherwise causes options to retain `tabindex=0` incorrectly when the popup is closed
// when tabbing outside.
if (!nextOpen && activeIndex !== null) {
const activeOption = listRef.current[activeIndex];
// Wait for Floating UI's focus effect to have fired
queueMicrotask(() => {
activeOption?.setAttribute('tabindex', '-1');
});
}
});

useAfterExitAnimation({
Expand Down
Loading