Skip to content
← UI Library

Searchable command list

A command palette with grouped actions, match highlighting, shortcut keys and full arrow-key and Enter control.

Svelte 5 · Version 1.0.0 · Zero extra packages

Connect MCP

Live preview

New project Start with a blank workspace ⌘N
Open activity See what changed this week
Invite a teammate Share your workspace ⌘I
Search documents Find a page by title ⌘P
Billing Plans, invoices and usage
Preferences Theme, shortcuts and alerts ⌘,
Toggle dark mode ⇧D

Design decision

Raycast’s audit highlights a working command bar as a product demo. Start with a few real tasks and keep actions reachable with ordinary keyboard controls.

Raycast audit ↗ · Site score 5

Source and integration

Pass items with id and label, plus optional description, group, shortcut keys and icon (plus, activity, user-plus, file, sliders, card, moon or command). Handle the onselect callback. Map the --ui-* variables to your tokens.

You may copy and adapt this original SaaSCrisp implementation in personal and commercial websites.

CommandList.svelte
<script module lang="ts">
	const icons = {
		plus: 'M12 5v14M5 12h14',
		activity: 'M22 12h-4l-3 9L9 3l-3 9H2',
		'user-plus': 'M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM19 8v6M22 11h-6',
		file: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8zM14 2v6h6',
		sliders: 'M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6',
		card: 'M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2zM2 10h20',
		moon: 'M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z',
		command: 'M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3'
	} as const;
	export type CommandIcon = keyof typeof icons;
</script>

<script lang="ts">
	type Item = {
		id: string;
		label: string;
		description?: string;
		group?: string;
		shortcut?: string[];
		icon?: CommandIcon;
	};
	let {
		items,
		onselect,
		label = 'Command menu',
		placeholder = 'Type a command or search…'
	}: { items: Item[]; onselect: (id: string) => void; label?: string; placeholder?: string } = $props();

	const id = $props.id();
	let query = $state('');
	let active = $state(0);
	let list: HTMLDivElement | undefined = $state();

	const needle = $derived(query.trim().toLowerCase());
	const groups = $derived.by(() => {
		const byGroup = new Map<string, Item[]>();
		for (const item of items) {
			const text = [item.label, item.description, item.group].join(' ').toLowerCase();
			if (!text.includes(needle)) continue;
			const key = item.group ?? '';
			byGroup.set(key, [...(byGroup.get(key) ?? []), item]);
		}
		let index = 0;
		return [...byGroup].map(([name, entries]) => ({
			name,
			entries: entries.map((item) => ({ item, index: index++ }))
		}));
	});
	const ordered = $derived(groups.flatMap((group) => group.entries.map((entry) => entry.item)));

	function optionId(index: number) {
		return `${id}-option-${index}`;
	}

	function move(step: number) {
		if (!ordered.length) return;
		active = (active + step + ordered.length) % ordered.length;
		list?.querySelector(`#${CSS.escape(optionId(active))}`)?.scrollIntoView({ block: 'nearest' });
	}

	function choose(index: number) {
		const item = ordered[index];
		if (!item) return;
		active = index;
		onselect(item.id);
	}

	function onkeydown(event: KeyboardEvent) {
		if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
			event.preventDefault();
			move(event.key === 'ArrowDown' ? 1 : -1);
		} else if (event.key === 'Enter') {
			event.preventDefault();
			choose(active);
		} else if (event.key === 'Escape' && query) {
			event.preventDefault();
			query = '';
			active = 0;
		}
	}

	function parts(text: string) {
		const at = needle ? text.toLowerCase().indexOf(needle) : -1;
		if (at < 0) return [{ text, hit: false }];
		return [
			{ text: text.slice(0, at), hit: false },
			{ text: text.slice(at, at + needle.length), hit: true },
			{ text: text.slice(at + needle.length), hit: false }
		].filter((part) => part.text);
	}
</script>

<div class="cmd">
	<div class="cmd-search">
		<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16zM21 21l-4.35-4.35" /></svg>
		<input
			bind:value={query}
			oninput={() => (active = 0)}
			{onkeydown}
			type="text"
			role="combobox"
			aria-label={label}
			aria-expanded="true"
			aria-controls="{id}-list"
			aria-autocomplete="list"
			aria-activedescendant={ordered.length ? optionId(active) : undefined}
			autocomplete="off"
			spellcheck="false"
			{placeholder}
		/>
		<kbd class="cmd-esc">esc</kbd>
	</div>

	<div class="cmd-list" bind:this={list} id="{id}-list" role="listbox" aria-label={label}>
		{#each groups as group (group.name)}
			<div role="group" aria-label={group.name || undefined}>
				{#if group.name}<div class="cmd-group" aria-hidden="true">{group.name}</div>{/if}
				{#each group.entries as { item, index } (item.id)}
					<div
						class="cmd-item"
						id={optionId(index)}
						role="option"
						tabindex="-1"
						aria-selected={index === active}
						onpointermove={() => (active = index)}
						onclick={() => choose(index)}
						onkeydown={(event) => event.key === 'Enter' && choose(index)}
					>
						<span class="cmd-icon" aria-hidden="true">
							<svg viewBox="0 0 24 24"><path d={icons[item.icon ?? 'command']} /></svg>
						</span>
						<span class="cmd-text">
							<span class="cmd-label">
								{#each parts(item.label) as part, partIndex (partIndex)}{#if part.hit}<mark>{part.text}</mark>{:else}{part.text}{/if}{/each}
							</span>
							{#if item.description}<span class="cmd-desc">{item.description}</span>{/if}
						</span>
						{#if item.shortcut?.length}
							<span class="cmd-keys" aria-label="Shortcut {item.shortcut.join(' ')}">
								{#each item.shortcut as key, keyIndex (keyIndex)}<kbd>{key}</kbd>{/each}
							</span>
						{/if}
					</div>
				{/each}
			</div>
		{:else}
			<p class="cmd-empty" role="status">No results for “{query.trim()}”</p>
		{/each}
	</div>

	<div class="cmd-foot" aria-hidden="true">
		<span class="cmd-brand"><span class="cmd-logo"></span>{label}</span>
		<span class="cmd-hints">
			<span>Open <kbd>↵</kbd></span>
			<span class="cmd-sep"></span>
			<span>Navigate <kbd>↑</kbd><kbd>↓</kbd></span>
		</span>
	</div>
</div>

<style>
	.cmd {
		--_bg: var(--ui-bg, #0f0f11);
		--_border: var(--ui-border, rgb(255 255 255 / 0.08));
		--_text: var(--ui-text, #ededf0);
		--_muted: var(--ui-muted, #8b8b94);
		--_accent: var(--ui-accent, #c8ff3c);
		overflow: hidden;
		border: 1px solid var(--_border);
		border-radius: var(--ui-radius, 16px);
		background:
			linear-gradient(180deg, rgb(255 255 255 / 0.03), transparent 120px),
			var(--_bg);
		color: var(--_text);
		font-family: var(--ui-font, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif);
		text-align: left;
		box-shadow:
			inset 0 1px 0 rgb(255 255 255 / 0.05),
			0 0 0 1px rgb(0 0 0 / 0.4),
			0 24px 60px -20px rgb(0 0 0 / 0.8);
	}
	.cmd-search {
		display: flex;
		align-items: center;
		gap: 10px;
		padding: 0 14px;
		border-bottom: 1px solid var(--_border);
	}
	.cmd-search > svg {
		flex-shrink: 0;
		width: 17px;
		height: 17px;
		fill: none;
		stroke: var(--_muted);
		stroke-width: 1.8;
		stroke-linecap: round;
	}
	input {
		flex: 1;
		min-width: 0;
		height: 52px;
		border: 0;
		outline: 0;
		background: none;
		color: var(--_text);
		font: inherit;
		font-size: 15px;
	}
	input::placeholder {
		color: var(--_muted);
	}
	kbd {
		display: inline-grid;
		place-items: center;
		min-width: 20px;
		height: 20px;
		padding: 0 5px;
		border: 1px solid var(--_border);
		border-radius: 5px;
		background: rgb(255 255 255 / 0.05);
		box-shadow: inset 0 -1px 0 rgb(255 255 255 / 0.04);
		color: var(--_muted);
		font: 500 11px/1 ui-sans-serif, system-ui, sans-serif;
	}
	.cmd-list {
		max-height: var(--ui-list-max-height, 19rem);
		overflow-y: auto;
		padding: 6px;
		scrollbar-width: thin;
		scroll-padding: 6px;
	}
	.cmd-group {
		padding: 10px 10px 6px;
		color: var(--_muted);
		font-size: 12px;
		font-weight: 500;
	}
	.cmd-item {
		display: flex;
		align-items: center;
		gap: 12px;
		min-height: 44px;
		padding: 6px 10px;
		border-radius: 10px;
		cursor: pointer;
		user-select: none;
	}
	.cmd-item[aria-selected='true'] {
		background: rgb(255 255 255 / 0.06);
		box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.04);
	}
	.cmd-icon {
		display: grid;
		flex-shrink: 0;
		place-items: center;
		width: 28px;
		height: 28px;
		border: 1px solid var(--_border);
		border-radius: 8px;
		background: linear-gradient(180deg, rgb(255 255 255 / 0.08), rgb(255 255 255 / 0.02));
		color: var(--_muted);
		transition: color 0.15s;
	}
	.cmd-item[aria-selected='true'] .cmd-icon {
		color: var(--_text);
	}
	.cmd-icon svg {
		width: 14px;
		height: 14px;
		fill: none;
		stroke: currentColor;
		stroke-width: 1.9;
		stroke-linecap: round;
		stroke-linejoin: round;
	}
	.cmd-text {
		display: flex;
		flex: 1;
		align-items: baseline;
		gap: 10px;
		min-width: 0;
	}
	.cmd-label {
		flex-shrink: 0;
		font-size: 14px;
		font-weight: 500;
	}
	.cmd-desc {
		overflow: hidden;
		color: var(--_muted);
		font-size: 13px;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	mark {
		background: none;
		color: var(--_accent);
	}
	.cmd-keys {
		display: flex;
		flex-shrink: 0;
		gap: 4px;
	}
	.cmd-empty {
		margin: 0;
		padding: 32px 16px;
		color: var(--_muted);
		font-size: 14px;
		text-align: center;
	}
	.cmd-foot {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		height: 42px;
		padding: 0 12px;
		border-top: 1px solid var(--_border);
		background: rgb(255 255 255 / 0.02);
		color: var(--_muted);
		font-size: 12px;
	}
	.cmd-brand,
	.cmd-hints,
	.cmd-hints > span {
		display: flex;
		align-items: center;
		gap: 6px;
	}
	.cmd-hints {
		gap: 10px;
	}
	.cmd-logo {
		width: 14px;
		height: 14px;
		border-radius: 4px;
		background: linear-gradient(135deg, var(--_accent), color-mix(in srgb, var(--_accent) 40%, #000));
	}
	.cmd-sep {
		width: 1px;
		height: 14px;
		background: var(--_border);
	}
	@media (max-width: 480px) {
		.cmd-desc,
		.cmd-keys,
		.cmd-brand {
			display: none;
		}
	}
</style>
Agent prompt

Use the SaaSCrisp UI Library MCP at https://www.saascrisp.com/api/library/mcp. Retrieve command-list version 1.0.0 for svelte with get_ui_asset. Preview: https://www.saascrisp.com/library/command-list. Confirm the project's stack, reuse local primitives and map CSS variables to existing design tokens. Integrate the files and run the project's checks. Report changed files and additional dependencies.