Browse docsCommand

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-command

Adds 12 files to components/glassyui and installs @radix-ui/react-dialog, clsx and cmdk.

Usage

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

Open with ⌘K

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);
}, []);
Shortcuts and keywords

<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.

PropTypeDefaultDescription
labelstringNoneAccessible name of the list. Not shown.
value / onValueChangestring / (value: string) => voidNoneThe highlighted item's value, and the handler that changes it.
shouldFilterbooleantrueSet to false to filter the items yourself.
filter(value: string, search: string, keywords?: string[]) => numbercmdk's fuzzy scoreScores each item from 0 (hidden) to 1 (best match).
loopbooleanfalseWraps 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.

PropTypeDefaultDescription
open / onOpenChangeboolean / (open: boolean) => voidNoneControlled open state and its handler.
titlestring'Command menu'Accessible name of the dialog. Not shown.
classNamestringNoneClasses for the glass panel.

Also accepts Radix Dialog.Root props.

GlassCommandInput

The search field, with a magnifier icon.

PropTypeDefaultDescription
value / onValueChangestring / (search: string) => voidNoneControlled 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

PropTypeDefaultDescription
headingReactNodeNoneThe group's heading. Without one, pass a unique value.

Also accepts cmdk Command.Group props.

GlassCommandItem

PropTypeDefaultDescription
onSelect(value: string) => voidNoneRuns on Enter or click.
valuestringthe item's textUnique value used for search and selection. Pass one if the text changes.
keywordsstring[]NoneExtra words the search matches.
disabledbooleanfalseSkips the item in navigation and selection.

Also accepts cmdk Command.Item props.

GlassCommandSeparator

A decorative divider between groups, hidden from assistive technology.

PropTypeDefaultDescription
alwaysRenderbooleanfalseKeeps 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.