Skip to main content

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​

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>
)
}
PropDescriptionTypeOptionsDefault
valueThe active item (controlled; plus's modelValue)string——
defaultValueThe active item (uncontrolled default)string——
modeLayout mode'horizontal' | 'vertical'—'vertical'
collapseFold the vertical menu into an icon bar (submenus become flyout panels)boolean—false
defaultOpenedsKeys of submenus expanded by default (uncontrolled)string[]—[]
openedsControlled keys of expanded submenusstring[]——
uniqueOpenedAccordion: expand at most one submenu at a timeboolean—false
sxShorthand layout propsSxProps——
PropDescriptionTypeDefault
indexUnique identifier (required; used as the active key)string—
disabledWhether to disable (tabindex -1 + aria-disabled)booleanfalse
childrenItem contentReactNode—
sxShorthand layout propsSxProps—

LhSubMenu Props​

PropDescriptionTypeDefault
indexUnique identifier (required; used as the expanded key)string—
titleTitle (ReactNode, plus's #title slot)ReactNode—
disabledWhether to disable (the submenu cannot be expanded)booleanfalse
childrenChild content (LhMenuItem / LhSubMenu, recursively nestable)ReactNode—
sxShorthand layout propsSxProps—
PropDescriptionTypeDefault
titleGroup title (ReactNode, plus's #title slot)ReactNode—
childrenItems inside the groupReactNode—
sxShorthand layout propsSxProps—
EventDescriptionCallback signatureVue equivalent
onSelectEmitted when a leaf item is selected (indexPath is the submenu key chain, e.g. ['works', 'works-list'])(index: string, indexPath: string[]) => void@select
onOpenEmitted when a submenu is expanded(index: string, indexPath: string[]) => void@open
onCloseEmitted when a submenu is collapsed(index: string, indexPath: string[]) => void@close
onOpenedsChangeEmitted when the expanded submenu keys change(openeds: string[]) => void@update:openeds
Controlled / uncontrolled

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'