Skip to content

Commit 18deecb

Browse files
committed
feat(react-roving-focus-group): use get-deep-active-element to cross the shadow DOM boundary
1 parent 35b1d00 commit 18deecb

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

packages/react/roving-focus/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"build": "radix-build"
3535
},
3636
"dependencies": {
37+
"@radix-ui/deep-active-element": "workspace:*",
3738
"@radix-ui/primitive": "workspace:*",
3839
"@radix-ui/react-collection": "workspace:*",
3940
"@radix-ui/react-compose-refs": "workspace:*",

packages/react/roving-focus/src/roving-focus-group.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useControllableState } from '@radix-ui/react-use-controllable-state';
1010
import { useDirection } from '@radix-ui/react-direction';
1111

1212
import type { Scope } from '@radix-ui/react-context';
13+
import { getDeepActiveElement } from '@radix-ui/deep-active-element'
1314

1415
const ENTRY_FOCUS = 'rovingFocusGroup.onEntryFocus';
1516
const EVENT_OPTIONS = { bubbles: false, cancelable: true };
@@ -325,12 +326,12 @@ function getFocusIntent(event: React.KeyboardEvent, orientation?: Orientation, d
325326
}
326327

327328
function focusFirst(candidates: HTMLElement[], preventScroll = false) {
328-
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
329+
const PREVIOUSLY_FOCUSED_ELEMENT = getDeepActiveElement();
329330
for (const candidate of candidates) {
330331
// if focus is already where we want to go, we don't want to keep going through the candidates
331332
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
332333
candidate.focus({ preventScroll });
333-
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
334+
if (getDeepActiveElement() !== PREVIOUSLY_FOCUSED_ELEMENT) return;
334335
}
335336
}
336337

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)