Skip to content

Command

Command palette for keyboard-first navigation and search.

Web Only

This component is only available for web frameworks (Vue, React, Angular). Keyboard-heavy command palettes are not suitable for mobile platforms.

Suggestions
CalendarCtrl+C
Search EmojiCtrl+E
CalculatorCtrl+K

Installation

bash
npx @galaxy-stack/nebula-cli add command
bash
npx @galaxy-stack/nebula-cli add command
bash
npx @galaxy-stack/nebula-cli add command
bash
# If you have installed galaxy-design globally
galaxy-design add command

Usage

tsx
import {
  Command,
  CommandDialog,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
  CommandSeparator,
  CommandShortcut,
} from '@/components/command'

export default function CommandDemo() {
  return (
    <Command className="rounded-lg border shadow-md">
      <CommandInput placeholder="Type a command or search..." />
      <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup heading="Suggestions">
          <CommandItem>
            <span>Calendar</span>
          </CommandItem>
          <CommandItem>
            <span>Search Emoji</span>
          </CommandItem>
          <CommandItem>
            <span>Calculator</span>
          </CommandItem>
        </CommandGroup>
        <CommandSeparator />
        <CommandGroup heading="Settings">
          <CommandItem>
            <span>Profile</span>
            <CommandShortcut>⌘P</CommandShortcut>
          </CommandItem>
          <CommandItem>
            <span>Settings</span>
            <CommandShortcut>⌘S</CommandShortcut>
          </CommandItem>
        </CommandGroup>
      </CommandList>
    </Command>
  )
}
vue
<script setup lang="ts">
import { Command } from '@/components/command'
</script>

<template>
  <Command class="rounded-lg border shadow-md" placeholder="Type a command or search...">
    <template #default="{ search }">
      <div class="p-1">
        <div v-if="!search">No results found.</div>
        <div v-else>
          <div class="px-2 py-1.5 text-xs font-medium text-muted-foreground">
            Suggestions
          </div>
          <button class="relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground">
            Calendar
          </button>
        </div>
      </div>
    </template>
  </Command>
</template>

API Reference

Props

PropTypeDefaultDescriptionFrameworks
valuestring-Controlled search valueReact, Vue, Angular
onValueChange(value: string) => void-Called when the search value changesReact, Vue, Angular
labelstring-Accessible label for the command menuReact, Vue, Angular
loopbooleanfalseWhether keyboard navigation loops through itemsReact, Vue, Angular
shouldFilterbooleantrueWhether automatic filtering is enabledReact, Vue, Angular
className / classstring""CSS class namesReact (className), Vue/Angular (class)
placeholderstring-Placeholder text for the search inputVue, Angular

Sub-components

CommandDialog

PropTypeDefaultDescriptionFrameworks
openboolean-Controlled open state for the dialogReact, Vue, Angular
defaultOpenbooleanfalseInitial open state for uncontrolled usageReact, Vue, Angular
onOpenChange(open: boolean) => void-Called when the dialog open state changesReact, Vue, Angular

CommandInput

PropTypeDefaultDescriptionFrameworks
placeholderstring-Placeholder textAll
className / classstring-CSS class namesReact (className), Vue/Angular (class)

CommandList

PropTypeDefaultDescriptionFrameworks
className / classstring-CSS class namesReact (className), Vue/Angular (class)

CommandGroup

PropTypeDefaultDescriptionFrameworks
headingstring-Group heading textAll
className / classstring-CSS class namesReact (className), Vue/Angular (class)

CommandItem

PropTypeDefaultDescriptionFrameworks
disabledbooleanfalseDisables the itemReact, Vue, Angular
onSelect(event: Event) => void-Called when the item is selectedReact, Vue, Angular
className / classstring-CSS class namesReact (className), Vue/Angular (class)

Components

  • Command - Main command container
  • CommandInput - Search input field
  • CommandList - Scrollable list of items
  • CommandEmpty - Shown when no results
  • CommandGroup - Group of related items
  • CommandItem - Individual command item
  • CommandSeparator - Visual separator
  • CommandShortcut - Keyboard shortcut display

Examples

Command Dialog

tsx
const [open, setOpen] = useState(false)

useEffect(() => {
  const down = (e: KeyboardEvent) => {
    if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
      e.preventDefault()
      setOpen((open) => !open)
    }
  }
  document.addEventListener('keydown', down)
  return () => document.removeEventListener('keydown', down)
}, [])

return (
  <CommandDialog open={open} onOpenChange={setOpen}>
    <CommandInput placeholder="Type a command or search..." />
    <CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
      <CommandGroup heading="Suggestions">
        <CommandItem>Calendar</CommandItem>
      </CommandGroup>
    </CommandList>
  </CommandDialog>
)

Accessibility

  • Keyboard navigation with arrow keys
  • Type-ahead search filtering
  • Proper ARIA labels and roles

Author

Bùi Trọng Hiếu (kevinbui)

License

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Released under the MIT License.