@command-palette/vue
v0.0.1
Published
Unstyled Vue command palette primitives
Maintainers
Readme
@command-palette/vue
Unstyled Vue primitives for building command menus.
Built on top of the internal command store.
Usage
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from '@command-palette/vue'
</script>
<template>
<Command label="Command Palette">
<CommandInput placeholder="Search…" />
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
<CommandGroup heading="Letters">
<CommandItem value="a">A</CommandItem>
<CommandItem value="b">B</CommandItem>
</CommandGroup>
<CommandItem value="apple" :keywords="['fruit']">Apple</CommandItem>
</CommandList>
</Command>
</template>For modal usage:
<script setup lang="ts">
import { ref } from 'vue'
import {
CommandDialog,
CommandInput,
CommandItem,
CommandList,
} from '@command-palette/vue'
const open = ref(false)
</script>
<template>
<CommandDialog v-model:open="open" label="Global Command Palette">
<CommandInput placeholder="Type a command…" />
<CommandList>
<CommandItem value="theme">Change theme</CommandItem>
<CommandItem value="settings">Open settings</CommandItem>
</CommandList>
</CommandDialog>
</template>Components
Command
Root provider and interactive command surface.
label?: stringAccessible label for the command surface.modelValue?: stringControlled highlighted item value.defaultValue?: stringInitial highlighted item value for uncontrolled usage.update:modelValueEmitted when the highlighted item changes.search?: stringControlled search query.defaultSearch?: stringInitial search query for uncontrolled usage.update:searchEmitted when the search query changes.filter?: 'fuzzy' | 'contains' | 'none' | FilterFnBuilt-in filter mode or a custom scoring function.loop?: booleanWrap keyboard navigation from end to start and back.selectOnHover?: booleanWhentrue, pointer hover updates selection. Defaults totrue.
CommandInput
Search input wired to the current command store.
- All normal
inputattributes modelValue?: stringOverride the displayed value.update:modelValueEmitted after the input value is committed.
IME composition is handled so partial composition does not trigger intermediate search updates.
CommandItem
Selectable command row.
value: stringStable item identity.keywords?: readonly string[]Extra aliases used by filtering.disabled?: booleanRenders the item but removes it from selection and keyboard navigation.forceMount?: booleanKeeps the item visible even when filtering would hide it.groupId?: stringExplicit group association. Usually inherited fromCommandGroup.selectEmitted when the item is activated.
CommandGroup
Groups related items under an optional heading. Hidden automatically when no item in the group is visible, unless forceMount is set.
CommandDialog
Native <dialog> wrapper around Command.
open: booleanControls whether the dialog is open.update:openEmitted when the dialog opens or closes.dialogClass?: stringClass name for the native<dialog>.resetSearchOnClose?: booleanClears uncontrolled search when closing. Defaults totrue.
Other components
CommandListListbox wrapper for items and groups.CommandEmptyOnly renders when no visible items remain.CommandSeparatorHidden while searching unlessalwaysRenderis set.CommandLoadingProgressbar helper for async states.
Composables
useCommandStore()Returns the underlying store instance.useCommandSlice(selector)Subscribes to derivedCommandState.
const count = useCommandSlice((state) => state.filteredOrder.length)Styling
The package is unstyled. Useful selectors:
[command-palette-root][command-palette-dialog][command-palette-input][command-palette-list][command-palette-item][command-palette-group][command-palette-group-heading][command-palette-group-items][command-palette-empty][command-palette-separator][command-palette-loading][data-selected][data-disabled]
