Skip to main content

Dropdown

Folds an action menu under a trigger and expands it on hover or click. The menu uses role="menu" semantics with full keyboard navigation (arrow keys / Home / End / Enter / Esc) and roving tabindex.

Basic usage​

Hover / click trigger and imperative usage
import { LhButton, LhDropdown, LhDropdownItem } from '@lh-ui/react'

export default function Demo() {
return (
<LhDropdown
onCommand={(command) => console.log(command)}
dropdown={
<>
<LhDropdownItem command="new">New</LhDropdownItem>
<LhDropdownItem command="delete" disabled>
Delete
</LhDropdownItem>
</>
}
>
<LhButton>Open</LhButton>
</LhDropdown>
)
}
PropDescriptionTypeOptionsDefault
childrenTrigger nodeReactNode——
dropdownMenu content (a list of LhDropdownItem, corresponding to the #dropdown slot of plus)ReactNode——
triggerTrigger method'hover' | 'click' | 'contextmenu'—'hover'
placementPlacementLhDropdownPlacementtop / bottom (with -start / -end), etc.'bottom-start'
disabledWhether to disableboolean—false
visibleControlled visibilityboolean——
defaultVisibleUncontrolled default visibilityboolean—false
hideOnClickWhether to auto-close after clicking a menu itemboolean—true
maxHeightMaximum menu height (scrolls when exceeded)string | number——
popperClassCustom menu class namestring——
themeVarsComponent-level theme variablesRecord<string, string>——
sxShorthand layout props (applied to the trigger)SxProps——
EventDescriptionCallback signatureVue equivalent
onCommandEmitted when a menu item is clicked, carrying the item's command(command: string | number) => voidcommand
onVisibleChangeEmitted when visibility changes(visible: boolean) => voidupdate:visible
onClickOutsideEmitted when clicking outside the menu (the menu also closes internally)() => voidclick-outside
PropDescriptionTypeOptionsDefault
childrenMenu item contentReactNode——
commandCommand identifier, emitted with onCommandstring | number——
disabledWhether to disable (does not respond to clicks and is skipped by keyboard navigation)boolean—false
dividedWhether to show a dividerboolean—false
EventDescriptionCallback signatureVue equivalent
onClickClicking the menu item (can coexist with onCommand)() => void—

ref​

forwardRef<LhDropdownInstance>. LhDropdownInstance exposes show() / hide() / toggle() / isVisible.

Keyboard navigation (APG menu pattern)

After opening the menu, focus lands on the first enabled item; ArrowUp / ArrowDown cycle through items and skip disabled ones, Home / End jump to the first / last item, Enter / Space activate the current item, and Esc closes the menu and returns focus to the trigger. Only the anchor item has tabIndex={0}; the rest are -1 (roving tabindex).

Slot → prop

plus uses a #dropdown slot for the menu; the React side uses a dropdown prop of the same name. The contextmenu trigger prevents the browser's default context menu.

Styles​

import '@lh-ui/react/style/dropdown'