Skip to content

Commit 95a4093

Browse files
committed
docs: menu
1 parent 3d613cf commit 95a4093

File tree

1 file changed

+47
-0
lines changed
  • website/src/content/pages/components

1 file changed

+47
-0
lines changed

website/src/content/pages/components/menu.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,53 @@ leverage it to access the component state and methods from outside the menu.
8282

8383
> If you're using the `RootProvider` component, you don't need to use the `Root` component.
8484
85+
## Guides
86+
87+
### Avoid passing custom ids to menu items
88+
89+
Ark UI autogenerates ids for menu items internally. Passing a custom `id` prop breaks the internal `getElementById`
90+
functionality used by the component.
91+
92+
```tsx
93+
// ❌ Don't do this
94+
<Menu.Item id="custom-id" value="custom-value">
95+
Custom Item
96+
</Menu.Item>
97+
98+
// ✅ Do this
99+
<Menu.Item value="custom-value">
100+
Custom Item
101+
</Menu.Item>
102+
```
103+
104+
### Menu items as links
105+
106+
To render a menu item as a link, render the link as the menu item itself using the `asChild` prop, not as a child of the
107+
menu item.
108+
109+
> This pattern ensures the link element receives the correct ARIA attributes and keyboard interactions from the menu
110+
> item.
111+
112+
Here's an example of a reusable `MenuItemLink` component:
113+
114+
```tsx
115+
interface MenuItemLinkProps extends Menu.ItemProps {
116+
href?: string
117+
target?: string
118+
}
119+
120+
export const MenuItemLink = (props: MenuItemLinkProps) => {
121+
const { href, target, children, ...rest } = props
122+
return (
123+
<Menu.Item {...rest} asChild>
124+
<a href={href} target={target}>
125+
{children}
126+
</a>
127+
</Menu.Item>
128+
)
129+
}
130+
```
131+
85132
## API Reference
86133

87134
### Props

0 commit comments

Comments
 (0)