Skip to content

Commit c0aaf24

Browse files
committed
feat(react-menu): use get-deep-active-element to cross the shadow DOM boundary
1 parent 024a2f7 commit c0aaf24

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

packages/react/menu/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/menu/src/menu.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { hideOthers } from 'aria-hidden';
2121
import { RemoveScroll } from 'react-remove-scroll';
2222

2323
import type { Scope } from '@radix-ui/react-context';
24+
import { getDeepActiveElement } from '@radix-ui/deep-active-element'
2425

2526
type Direction = 'ltr' | 'rtl';
2627

@@ -397,7 +398,7 @@ const MenuContentImpl = React.forwardRef<MenuContentImplElement, MenuContentImpl
397398
const handleTypeaheadSearch = (key: string) => {
398399
const search = searchRef.current + key;
399400
const items = getItems().filter((item) => !item.disabled);
400-
const currentItem = document.activeElement;
401+
const currentItem = getDeepActiveElement();
401402
const currentMatch = items.find((item) => item.ref.current === currentItem)?.textValue;
402403
const values = items.map((item) => item.textValue);
403404
const nextMatch = getNextMatch(values, search, currentMatch);
@@ -1238,12 +1239,12 @@ function getCheckedState(checked: CheckedState) {
12381239
}
12391240

12401241
function focusFirst(candidates: HTMLElement[]) {
1241-
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
1242+
const PREVIOUSLY_FOCUSED_ELEMENT = getDeepActiveElement();
12421243
for (const candidate of candidates) {
12431244
// if focus is already where we want to go, we don't want to keep going through the candidates
12441245
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
12451246
candidate.focus();
1246-
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
1247+
if (getDeepActiveElement() !== PREVIOUSLY_FOCUSED_ELEMENT) return;
12471248
}
12481249
}
12491250

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)