OverlaysReact
A command palette: a dialog holding a search input and a list of commands.
Rendered by React 19.3.1
Loading React…Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<Spotlight.Root>
<Spotlight.Trigger />
<Spotlight.Portal>
<Spotlight.Backdrop />
<Spotlight.Popup>
<Spotlight.Title />
<Spotlight.Description />
<Spotlight.Input />
<Spotlight.Empty />
<Spotlight.List>
<Spotlight.Collection>
<Spotlight.Group>
<Spotlight.GroupLabel>
<Spotlight.Item />
</Spotlight.GroupLabel>
</Spotlight.Group>
</Spotlight.Collection>
</Spotlight.List>
<Spotlight.Status />
<Spotlight.Close />
</Spotlight.Popup>
</Spotlight.Portal>
</Spotlight.Root>
// Not in this example: Spotlight.Separator, Spotlight.ViewportExamples
The demo at the top is the one example this component has so far.
API reference
48 props across 18 parts, in React syntax. className, style, render are listed once, under Shared props.
BackdropSpotlight.Backdrop
An overlay displayed beneath the popup. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
forceRenderWhether the backdrop is forced to render even when nested. | boolean | false |
| Data attribute | Description |
|---|---|
data-open | Present when the spotlight is open. |
data-closed | Present when the spotlight is closed. |
data-starting-style | Present when the spotlight begins animating in. |
data-ending-style | Present when the spotlight is animating out. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
CloseSpotlight.Close
A button that closes the spotlight. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
| Data attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
CollectionSpotlight.Collection
Renders the filtered commands, or the commands of its Spotlight.Group. If rendering a flat list, pass a function child to the List component instead, which implicitly wraps it. Doesn’t render its own element.
| Prop | Type | Default |
|---|---|---|
childrenrequired | (item: any, index: number) => React.ReactNode | — |
DescriptionSpotlight.Description
A paragraph with additional information about the spotlight. Renders a <p>.
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
EmptySpotlight.Empty
Renders its children only when no command matches the query. Announces changes politely to screen readers. Keep it mounted and outside Spotlight.List. Renders a <div>.
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
GroupSpotlight.Group
Groups related commands with the corresponding label. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
itemsItems to be rendered within this group. | readonly any[] | — |
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
GroupLabelSpotlight.GroupLabel
An accessible label that is automatically associated with its parent group. Renders a <div>.
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
InputSpotlight.Input
A text input to search the commands. It is a combobox that controls the list, and the popup's initial focus. Renders an <input>.
| Prop | Type | Default |
|---|---|---|
disabledWhether the component should ignore user interaction. | boolean | false |
| Data attribute | Description |
|---|---|
data-popup-open | Present when the corresponding popup is open. |
data-pressed | Present when the input is pressed. |
data-disabled | Present when the component is disabled. |
data-readonly | Present when the component is readonly. |
data-popup-side | Indicates which side the corresponding popup is positioned relative to its anchor. |
data-required | Present when the component is required. |
data-valid | Present when the component is in a valid state (when wrapped in Field.Root). |
data-invalid | Present when the component is in an invalid state (when wrapped in Field.Root). |
data-touched | Present when the component has been touched (when wrapped in Field.Root). |
data-dirty | Present when the component's value has changed (when wrapped in Field.Root). |
data-filled | Present when the component has a value (when wrapped in Field.Root). |
data-focused | Present when the input is focused (when wrapped in Field.Root). |
data-list-empty | Present when the corresponding items list is empty. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
ItemSpotlight.Item
A command in the list. A press (a click, a tap, or <kbd>Enter</kbd> while it is highlighted) runs its onClick, then closes the spotlight. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | false |
children | React.ReactNode | — |
onClickA click handler that runs the command. | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | — |
closeOnClickWhether pressing the item closes the spotlight, with the reason 'item-press'. | boolean | true |
indexThe index of the item in the list. | number | — |
valueA unique value that identifies this item. | any | null |
disabledWhether the component should ignore user interaction. | boolean | false |
| Data attribute | Description |
|---|---|
data-highlighted | Present when the item is highlighted. |
data-disabled | Present when the item is disabled. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
ListSpotlight.List
The list of commands, always shown: a listbox the input controls. Keep Spotlight.Empty and Spotlight.Status outside it. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
children | React.ReactNode | ((item: any, index: number) => React.ReactNode) | — |
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
PopupSpotlight.Popup
A container for the spotlight contents: the dialog, which holds the search input and the list. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
initialFocusDetermines the element to focus when the spotlight is opened. | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null) | — |
finalFocusDetermines the element to focus when the spotlight is closed. | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null) | — |
| Data attribute | Description |
|---|---|
data-open | Present when the spotlight is open. |
data-closed | Present when the spotlight is closed. |
data-starting-style | Present when the spotlight begins animating in. |
data-ending-style | Present when the spotlight is animating out. |
data-nested | Present when the spotlight is nested within another dialog. |
data-nested-dialog-open | Present when the spotlight has other open dialogs nested within it. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
| CSS variable | Description |
|---|---|
--nested-dialogs | Indicates how many dialogs are nested within. |
PortalSpotlight.Portal
A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
keepMountedWhether to keep the portal mounted in the DOM while the popup is hidden. | boolean | false |
containerA parent element to render the portal element into. | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | — |
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
RootSpotlight.Root
Groups all parts of the spotlight: a command palette, a modal dialog holding a search input and an inline list of commands. Doesn’t render its own element.
| Prop | Type | Default |
|---|---|---|
openWhether the spotlight is currently open. | boolean | — |
defaultOpenWhether the spotlight is initially open. | boolean | false |
onOpenChangeEvent handler called when the spotlight is opened or closed. | ((open: boolean, eventDetails: SpotlightRootChangeEventDetails) => void) | — |
onOpenChangeCompleteEvent handler called after any animations complete when the spotlight is opened or closed. | ((open: boolean) => void) | — |
modalDetermines if the spotlight enters a modal state when open. | boolean | "trap-focus" | true |
disablePointerDismissalWhether to prevent the spotlight from closing on outside presses. | boolean | false |
actionsRefA ref to imperative actions. | React.RefObject<SpotlightRootActions | null> | — |
handleA handle to associate the spotlight with a trigger. | SpotlightHandle<Payload> | — |
triggerIdID of the trigger that the spotlight is associated with. | string | null | — |
defaultTriggerIdID of the trigger that the spotlight is associated with. | string | null | — |
hotkeyA hotkey that opens the spotlight, and closes it while open, such as 'Mod+K'. | string | — |
itemsThe commands to be displayed in the list. | readonly ItemValue[] | readonly Group<ItemValue>[] | — |
filteredItemsFiltered commands to display in the list. | readonly ItemValue[] | readonly Group<ItemValue>[] | — |
filterFilter function used to match items against the query. | ((item: ItemValue, query: string, itemToString?: ((item: ItemValue) => string) | undefined) => boolean) | null | — |
limitThe maximum number of items to display in the list. | number | -1 |
localeThe locale to use for string comparison. | Intl.LocalesArgument | — |
valueThe query typed in the input. | string | — |
defaultValueThe uncontrolled query when the spotlight is initially rendered. | string | — |
onValueChangeEvent handler called when the query changes. | ((value: string, eventDetails: AutocompleteRootChangeEventDetails) => void) | — |
itemToStringValueWhen the item values are objects, this function converts the object value to a string | ((itemValue: ItemValue) => string) | — |
onItemHighlightedCallback fired when an item is highlighted or unhighlighted. | ((highlightedValue: ItemValue | undefined, eventDetails: AriaCombobox.HighlightEventDetails) => void) | — |
highlightItemOnHoverWhether moving the pointer over items should highlight them. | boolean | true |
loopFocusWhether to loop keyboard focus back to the input when the end of the list is reached while using the arrow keys. | boolean | true |
virtualizedWhether the items are being externally virtualized. | boolean | false |
childrenThe content of the spotlight. | React.ReactNode | PayloadChildRenderFunction<Payload> | — |
SeparatorSpotlight.Separator
A visual separator between commands or groups. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
orientationThe orientation of the separator. | Orientation | 'horizontal' |
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
StatusSpotlight.Status
Announces the result count politely to screen readers once the query has settled. Renders its children only while the query is not empty, at least one command matches, and the query has not changed for delay milliseconds. Keep it mounted and outside Spotlight.List. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
delayHow long the query must stay unchanged before the children are rendered, in milliseconds. | number | 1000 |
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
TitleSpotlight.Title
A heading that labels the spotlight. Renders a <h2>.
| Data attribute | Description |
|---|---|
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
TriggerSpotlight.Trigger
A button that opens the spotlight. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
handleA handle to associate the trigger with a spotlight. | SpotlightHandle<Payload> | — |
payloadA payload to pass to the spotlight when it is opened. | Payload | — |
idID of the trigger. | string | — |
| Data attribute | Description |
|---|---|
data-disabled | Present when the trigger is disabled. |
data-popup-open | Present when the corresponding dialog is open. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
ViewportSpotlight.Viewport
A positioning container for the spotlight popup that can be made scrollable. Renders a <div>.
| Data attribute | Description |
|---|---|
data-open | Present when the spotlight is open. |
data-closed | Present when the spotlight is closed. |
data-starting-style | Present when the spotlight begins animating in. |
data-ending-style | Present when the spotlight is animating out. |
data-nested | Present when the spotlight is nested within another dialog. |
data-nested-dialog-open | Present when the spotlight has other open dialogs nested within it. |
data-slot | Names the part for styling: the component's id on its root (switch), <component>-<part> on the others (popover-popup). A value you set on the part wins. |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
| Keys | Does | Part |
|---|---|---|
| Mod+K | Opens and closes the palette | |
| ↑ ↓ | Moves between the commands | |
| Enter | Runs the highlighted command | |
| Esc | Closes the palette |
Accessibility
Not written yet.