Introducing PrimeReact v11-alpha 🎉Discover Now

CommandMenu

An unstyled searchable command palette with grouped items and keyboard navigation.

Build fully custom command palettes with complete control over layout and styling.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use CommandMenu with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, Header, Input, List, Item, Group, GroupHeader, Footer, Empty
  • Score-based filtering with support for custom filter functions and keyword matching
  • Grouped option rendering with automatic group filtering and sorting by relevance
  • Auto-focus management with scroll-into-view for the active item

Usage#

import { CommandMenu } from 'primereact/commandmenu';
<CommandMenu>
    <CommandMenu.Input />
    <CommandMenu.Empty></CommandMenu.Empty>
    <CommandMenu.List>
        <CommandMenu.Group>
            <CommandMenu.GroupHeading></CommandMenu.GroupHeading>
            <CommandMenu.Item></CommandMenu.Item>
        </CommandMenu.Group>
    </CommandMenu.List>
</CommandMenu>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<CommandMenu.Root as="section">...</CommandMenu.Root>

Render Function Children#

CommandMenu.List accepts a render function providing access to the command menu instance.

<CommandMenu.List>{({ commandmenu }) => <div>{commandmenu.filteredCount} results</div>}</CommandMenu.List>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

CommandMenuRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuRootInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
optionsunknown[]—
An array of options to display in the command menu.
optionLabelstring—
Property name to use as the display label for options.
optionValuestring—
Property name to use as the value for options.
optionDisabledstring—
Property name to check if an option is disabled.
optionGroupLabelstring—
Property name for the group label when using grouped options.
optionGroupChildrenstring—
Property name for the group children when using grouped options.
optionKeywordsstring—
Property name for keywords array on option objects (used for search matching).
searchstring—
The controlled search value.
defaultSearchstring—
The default search value for uncontrolled mode.
onSearchChange(event: useCommandMenuSearchChangeEvent) => void—
Callback fired when the search value changes.
onItemSelect(event: useCommandMenuItemSelectEvent) => void—
Callback fired when an item is selected (via Enter key or click).
filter(label: string, search: string, keywords?: string[]) => number—
Custom filter/scoring function. Returns a numeric score (0 = no match, higher = better match).
selectOnHoverboolean—
Whether to highlight items on hover.
loopboolean—
Whether keyboard navigation loops around from last to first item.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"commandmenu"
data-part"root"

Defines passthrough(pt) options of CommandMenu component.

labeltypedescription
rootCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
listCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the list's DOM element.
groupCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the group's DOM element.
groupheaderCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the group header's DOM element.
itemCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the item's DOM element.
emptyCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the empty's DOM element.
headerCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the header's DOM element.
footerCommandMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the footer's DOM element.
inputCommandMenuRootPassThroughType<HTMLAttributes<HTMLInputElement>>Used to pass attributes to the input's DOM element.

CommandMenuInput#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuInputInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuInputInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuInputInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuInputPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuInputInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valuestring—
Value of the input.
onValueChange(value: string) => void—
Callback function that is called when the value changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"commandmenu"
data-part"input"

Defines passthrough(pt) options of CommandMenuInput component.

labeltypedescription
rootCommandMenuInputPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuList#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuListInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuListInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuListInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuListPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuListInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"commandmenu"
data-part"list"

Defines passthrough(pt) options of CommandMenuList component.

labeltypedescription
rootCommandMenuListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuItem#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuItemInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuItemInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuItemInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuItemPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuItemInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
indexnumber—
The index of the item in the flattened options array. If not provided but `option` is, the index is resolved automatically.
optionunknown—
The option object reference. Used to automatically resolve the flat index when `index` is not explicitly provided.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-selectedPresent when item is focused
data-disabledPresent when item is disabled

Defines passthrough(pt) options of CommandPaletteItem component.

labeltypedescription
rootCommandMenuItemPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuGroup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuGroupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuGroupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuGroupInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuGroupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuGroupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"commandmenu"
data-part"group"

Defines passthrough(pt) options of CommandMenuGroup component.

labeltypedescription
rootCommandMenuGroupPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuGroupHeader#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuGroupHeaderInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuGroupHeaderInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuGroupHeaderInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuGroupHeaderPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuGroupHeaderInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of CommandMenuGroupHeader component.

labeltypedescription
rootCommandMenuGroupHeaderPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuHeader#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuHeaderInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuHeaderInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuHeaderInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuHeaderPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuHeaderInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of CommandMenuHeader component.

labeltypedescription
rootCommandMenuHeaderPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuFooter#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuFooterInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuFooterInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuFooterInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuFooterPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuFooterInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of CommandMenuFooter component.

labeltypedescription
rootCommandMenuFooterPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CommandMenuEmpty#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CommandMenuEmptyInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CommandMenuEmptyInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCommandMenuEmptyInstance—
The instance to pass to the component.
ptSafeRecord<CommandMenuEmptyPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CommandMenuEmptyInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of CommandMenuEmpty component.

labeltypedescription
rootCommandMenuEmptyPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

CommandMenu renders a combobox with an input (role="combobox") that controls a list of options (role="listbox"). Items use aria-selected to reflect the current selection and aria-disabled="true" when an item cannot be chosen. The accessible name can be overridden with aria-label or aria-labelledby on the root component.

Keyboard Support#

Key / ComboFunction
ArrowDown / ArrowUpMove to next / previous item
Home / EndMove to first / last item
EnterSelects the active item (ignored when disabled)