You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(cmdk): Update story to JSX-powered command palette API
Replace the useCommandPaletteActions hook example with the new JSX
component API using CMDKAction, CMDKGroup, and CommandPaletteProvider.
Also adds a section documenting the async resource pattern.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use `useCommandPaletteActions(actions)` inside your page or feature component to register contextual actions with the global command palette. Actions are registered on mount and automatically unregistered on unmount, so they only appear in the palette while your component is rendered. This is ideal for page‑specific shortcuts.
21
+
Use `CMDKAction` and `CMDKGroup` JSX components inside your page or feature component to register contextual actions with the global command palette. Actions are registered on mount and automatically unregistered on unmount, so they only appear in the palette while your component is rendered. This is ideal for page‑specific shortcuts.
24
22
25
-
There are a few different types of actions you can register:
23
+
Wrap your tree in `CommandPaletteProvider` and place the `CommandPalette` UI component wherever you want the dialog to render. Then declare actions anywhere inside the provider:
26
24
27
-
-**Navigation actions**: Provide a `to`destination to navigate to when selected.
25
+
-**Navigation actions**: Provide a `to`prop to navigate when selected.
28
26
-**Callback actions**: Provide an `onAction` handler to execute when selected.
29
-
-**Nested actions**: Provide an `actions: CommandPaletteAction[]` array on a parent item to show a second level. Selecting the parent reveals its children.
27
+
-**Grouped actions**: Wrap `CMDKAction` children inside a `CMDKGroup` to show a second level. Selecting the parent reveals its children.
28
+
-**Async actions**: Provide a `resource` prop to a `CMDKGroup` and use the render-prop children signature to generate actions from fetched data.
30
29
31
30
<Storybook.Demo>
32
31
<Flexwidth="100%">
@@ -35,34 +34,92 @@ There are a few different types of actions you can register:
{/* The command palette UI — also accepts inline actions via children */}
85
+
<CommandPaletteonAction={handleAction}>
86
+
<CMDKGroupdisplay={{label: 'Issues List'}}>
87
+
<CMDKAction
88
+
display={{label: 'Select all'}}
89
+
onAction={() =>addSuccessMessage('Select all')}
90
+
/>
91
+
<CMDKAction
92
+
display={{label: 'Deselect all'}}
93
+
onAction={() =>addSuccessMessage('Deselect all')}
94
+
/>
95
+
</CMDKGroup>
96
+
</CommandPalette>
97
+
</CommandPaletteProvider>
98
+
);
67
99
}
68
100
```
101
+
102
+
## Async / Resource Actions
103
+
104
+
`CMDKGroup` accepts a `resource` prop — a function that takes the current search query and returns a TanStack Query options object. The `children` prop becomes a render function that receives the fetched results:
0 commit comments