Skip to content

Commit 372d724

Browse files
authored
fix(dropdown): Apply href to aria links for dropdown children (#96004)
1 parent 27233f5 commit 372d724

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

static/app/components/dropdownMenu/index.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export type {MenuItemProps};
1818

1919
/**
2020
* Recursively removes hidden items, including those nested in submenus
21+
* Apply href to items that have a to or externalHref prop
2122
*/
22-
function removeHiddenItems(source: MenuItemProps[]): MenuItemProps[] {
23+
function removeHiddenItemsAndSetHref(source: MenuItemProps[]): MenuItemProps[] {
2324
return source
2425
.filter(item => !item.hidden)
2526
.map(item => ({
2627
...item,
27-
...(item.children ? {children: removeHiddenItems(item.children)} : {}),
28+
// react-aria uses the href prop on item state to determine if the item is a link
29+
href: item.to ?? item.externalHref,
30+
...(item.children ? {children: removeHiddenItemsAndSetHref(item.children)} : {}),
2831
}));
2932
}
3033

@@ -221,17 +224,7 @@ function DropdownMenu({
221224
);
222225
}
223226

224-
const activeItems = useMemo(
225-
() =>
226-
removeHiddenItems(items).map(item => {
227-
return {
228-
...item,
229-
// react-aria uses the href prop on item state to determine if the item is a link
230-
href: item.to ?? item.externalHref,
231-
};
232-
}),
233-
[items]
234-
);
227+
const activeItems = useMemo(() => removeHiddenItemsAndSetHref(items), [items]);
235228
const defaultDisabledKeys = useMemo(() => getDisabledKeys(activeItems), [activeItems]);
236229

237230
function renderMenu() {

0 commit comments

Comments
 (0)