Menu
A navigation menu component with horizontal / vertical layout modes, inline submenu expansion and flyout panels, collapse to an icon bar, accordion mode, and full keyboard navigation.
Basic usage
Selected: gallery
import { useState } from 'react'
import { LhMenu, LhMenuItem, LhSubMenu } from '@lh-ui/react'
export default function Demo() {
const [active, setActive] = useState('gallery')
return (
<LhMenu defaultValue="gallery" defaultOpeneds={['works']} onSelect={(key) => setActive(key)}>
<LhMenuItem index="gallery">Gallery home</LhMenuItem>
<LhSubMenu index="works" title="Works">
<LhMenuItem index="works-list">Works list</LhMenuItem>
<LhMenuItem index="works-upload">Upload work</LhMenuItem>
</LhSubMenu>
<LhMenuItem index="coming" disabled>
Coming soon
</LhMenuItem>
</LhMenu>
)
}
Horizontal mode
With mode="horizontal" the root becomes a top bar menu (role="menubar"); submenus fly out below the trigger on hover / click, and nested submenus fly out to the right.
import { LhMenu, LhMenuItem, LhSubMenu } from '@lh-ui/react'
export default function Demo() {
return (
<LhMenu mode="horizontal" defaultValue="home">
<LhMenuItem index="home">Home</LhMenuItem>
<LhSubMenu index="works" title="Works">
<LhMenuItem index="works-list">Works list</LhMenuItem>
<LhMenuItem index="works-upload">Upload work</LhMenuItem>
</LhSubMenu>
</LhMenu>
)
}
Collapse and accordion
In vertical mode, pass collapse to fold the menu into an icon bar (submenus become flyout panels); uniqueOpened enables the accordion: at most one submenu is expanded at a time, and clicking it again collapses it (collapsing everything is allowed).
import { LhMenu, LhMenuItem, LhSubMenu } from '@lh-ui/react'
export default function Demo() {
return (
<LhMenu collapse uniqueOpened defaultValue="works-list" defaultOpeneds={['works']}>
<LhSubMenu index="works" title="Works">
<LhMenuItem index="works-list">Works list</LhMenuItem>
<LhMenuItem index="works-upload">Upload work</LhMenuItem>
</LhSubMenu>
<LhSubMenu index="settings" title="Account settings">
<LhMenuItem index="profile">Profile</LhMenuItem>
</LhSubMenu>
</LhMenu>
)
}
Groups
LhMenuItemGroup renders a non-selectable group title above its children.
import { LhMenu, LhMenuItem, LhMenuItemGroup } from '@lh-ui/react'
export default function Demo() {
return (
<LhMenu>
<LhMenuItemGroup title="Group one">
<LhMenuItem index="a">Item A</LhMenuItem>
<LhMenuItem index="b">Item B</LhMenuItem>
</LhMenuItemGroup>
<LhMenuItemGroup title="Group two">
<LhMenuItem index="c">Item C</LhMenuItem>
</LhMenuItemGroup>
</LhMenu>
)
}
Menu Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | The active item (controlled; plus's modelValue) | string | — | — |
| defaultValue | The active item (uncontrolled default) | string | — | — |
| mode | Layout mode | 'horizontal' | 'vertical' | — | 'vertical' |
| collapse | Fold the vertical menu into an icon bar (submenus become flyout panels) | boolean | — | false |
| defaultOpeneds | Keys of submenus expanded by default (uncontrolled) | string[] | — | [] |
| openeds | Controlled keys of expanded submenus | string[] | — | — |
| uniqueOpened | Accordion: expand at most one submenu at a time | boolean | — | false |
| sx | Shorthand layout props | SxProps | — | — |
MenuItem Props
| Prop | Description | Type | Default |
|---|---|---|---|
| index | Unique identifier (required; used as the active key) | string | — |
| disabled | Whether to disable (tabindex -1 + aria-disabled) | boolean | false |
| children | Item content | ReactNode | — |
| sx | Shorthand layout props | SxProps | — |
LhSubMenu Props
| Prop | Description | Type | Default |
|---|---|---|---|
| index | Unique identifier (required; used as the expanded key) | string | — |
| title | Title (ReactNode, plus's #title slot) | ReactNode | — |
| disabled | Whether to disable (the submenu cannot be expanded) | boolean | false |
| children | Child content (LhMenuItem / LhSubMenu, recursively nestable) | ReactNode | — |
| sx | Shorthand layout props | SxProps | — |
MenuItemGroup Props
| Prop | Description | Type | Default |
|---|---|---|---|
| title | Group title (ReactNode, plus's #title slot) | ReactNode | — |
| children | Items inside the group | ReactNode | — |
| sx | Shorthand layout props | SxProps | — |
Menu events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onSelect | Emitted when a leaf item is selected (indexPath is the submenu key chain, e.g. ['works', 'works-list']) | (index: string, indexPath: string[]) => void | @select |
| onOpen | Emitted when a submenu is expanded | (index: string, indexPath: string[]) => void | @open |
| onClose | Emitted when a submenu is collapsed | (index: string, indexPath: string[]) => void | @close |
| onOpenedsChange | Emitted when the expanded submenu keys change | (openeds: string[]) => void | @update:openeds |
Passing value makes the component controlled; passing defaultValue uses the internal uncontrolled state. The expanded submenu keys work the same way (openeds / defaultOpeneds / onOpenedsChange). Callbacks fire in both modes. A nested submenu's onSelect bubbles up the chain (matching plus's nested re-provide), with indexPath accumulated by prepending each level's index.
Keyboard interaction
In vertical mode the root node delegates ↑/↓ focus traversal: visible items are leaf items plus submenu titles (DOM order equals visual order), cycling across submenu title ↔ panel item boundaries while skipping disabled items and items inside collapsed panels; Home / End jump to the first / last visible item. Leaf items activate with Enter / Space; submenu titles expand with Enter / Space / → (and collapse with ← / Escape). Horizontal mode keeps the title's own → / ← semantics and skips the root's vertical traversal.
Accessibility
The root is role="menu" in vertical mode and role="menubar" in horizontal mode; leaf items are role="menuitem" with aria-disabled when disabled; submenu titles are role="menuitem" with aria-expanded / aria-haspopup / aria-controls, and panels are role="menu" labeled via aria-label (from the shared locale key menu.submenuLabel); collapsed inline panels are removed from the accessibility tree with aria-hidden.
ref
forwardRef<HTMLUListElement> — the root list element.
Styles
import '@lh-ui/react/theme.css'
import '@lh-ui/react/style/menu'