OverlaysNew
Glass Command
A searchable command list that filters as you type, alone or in a dialog.
Preview
Demos ready. Update 0.
Installation
For React 19+ apps with Tailwind CSS 4.
npx shadcn@4.14.1 add @glassyui/glass-commandAdds 12 files to components/glassyui and installs @radix-ui/react-dialog, clsx and cmdk.
Usage
import {
GlassCommand,
GlassCommandDialog,
GlassCommandEmpty,
GlassCommandGroup,
GlassCommandInput,
GlassCommandItem,
GlassCommandList,
} from "@/components/glassyui/glass-command";
export function Launcher({ open, onOpenChange }: { open: boolean; onOpenChange: (open: boolean) => void }) {
return (
<GlassCommandDialog open={open} onOpenChange={onOpenChange}>
<GlassCommand label="Commands">
<GlassCommandInput placeholder="Type a command or search…" />
<GlassCommandList>
<GlassCommandEmpty>No results found.</GlassCommandEmpty>
<GlassCommandGroup heading="Suggestions">
<GlassCommandItem onSelect={() => onOpenChange(false)}>New file</GlassCommandItem>
</GlassCommandGroup>
</GlassCommandList>
</GlassCommand>
</GlassCommandDialog>
);
}Examples
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
event.preventDefault();
setOpen((current) => !current);
}
};
document.addEventListener("keydown", onKeyDown);
return () => document.removeEventListener("keydown", onKeyDown);
}, []);<GlassCommandItem keywords={["dark", "light"]} onSelect={toggleTheme}>
Switch theme
<GlassCommandShortcut>
<GlassKbdGroup><GlassKbd>⌘</GlassKbd><GlassKbd>T</GlassKbd></GlassKbdGroup>
</GlassCommandShortcut>
</GlassCommandItem>API reference
GlassCommand
The searchable list, with no glass of its own. Place it in GlassCommandDialog, a GlassPanel or a GlassPopover.
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | None | Accessible name of the list. Not shown. |
value / onValueChange | string / (value: string) => void | None | The highlighted item's value, and the handler that changes it. |
shouldFilter | boolean | true | Set to false to filter the items yourself. |
filter | (value: string, search: string, keywords?: string[]) => number | cmdk's fuzzy score | Scores each item from 0 (hidden) to 1 (best match). |
loop | boolean | false | Wraps the arrow keys from the last item to the first. |
Also accepts cmdk Command props.
GlassCommandDialog
A glass dialog near the top of the page that holds a GlassCommand.
| Prop | Type | Default | Description |
|---|---|---|---|
open / onOpenChange | boolean / (open: boolean) => void | None | Controlled open state and its handler. |
title | string | 'Command menu' | Accessible name of the dialog. Not shown. |
className | string | None | Classes for the glass panel. |
Also accepts Radix Dialog.Root props.
GlassCommandInput
The search field, with a magnifier icon.
| Prop | Type | Default | Description |
|---|---|---|---|
value / onValueChange | string / (search: string) => void | None | Controlled search text and its handler. |
Also accepts cmdk Command.Input props.
GlassCommandList
The scrolling results. Its height follows the results, up to 22rem or 60% of the viewport.
Also accepts cmdk Command.List props.
GlassCommandEmpty
Shown only when the search matches nothing.
Also accepts cmdk Command.Empty props.
GlassCommandGroup
| Prop | Type | Default | Description |
|---|---|---|---|
heading | ReactNode | None | The group's heading. Without one, pass a unique value. |
Also accepts cmdk Command.Group props.
GlassCommandItem
| Prop | Type | Default | Description |
|---|---|---|---|
onSelect | (value: string) => void | None | Runs on Enter or click. |
value | string | the item's text | Unique value used for search and selection. Pass one if the text changes. |
keywords | string[] | None | Extra words the search matches. |
disabled | boolean | false | Skips the item in navigation and selection. |
Also accepts cmdk Command.Item props.
GlassCommandSeparator
A decorative divider between groups, hidden from assistive technology.
| Prop | Type | Default | Description |
|---|---|---|---|
alwaysRender | boolean | false | Keeps the divider while a search is typed; by default it hides. |
Also accepts HTML div attributes.
GlassCommandShortcut
A shortcut hint pushed to the end of an item. Put GlassKbd keys inside.
Also accepts HTML span attributes.
- Types
GlassCommandDialogPropsGlassCommandSeparatorProps- Accessibility
- GlassCommandDialog returns focus to the element that had it when the dialog opened, unless the chosen command has moved focus elsewhere.