Tiem Cong Nghe

Showing suggestions.

Opening the store's index…
↑↓ to move↵ to openesc to close
Tiem Cong Nghe search
Componentv1.0.0~8 KB gzipped

Command Palette

A ⌘K command palette that finds any page or action in a few keystrokes

FreeFree
Format

.zip · HTML / CSS / JS · v1.0.0

Free — no account, no email. Always the newest version.

Live preview

Version
Preview width
Zoom

About

The fastest way around an app is to type what you want. Press ⌘K (Ctrl+K on Windows and Linux) and a frosted-glass panel drops in over a softly blurred page. Start typing: "gs" finds "Go to settings", "tgl" finds "Toggle theme", "cai dat" finds "Cài đặt". Arrow down, press Enter, done — and next time it is waiting at the top under Recent.

  • Fuzzy matching that rewards whole words and runs of letters, so the best result comes first
  • Commands grouped into sections, each with an optional icon and shortcut hint
  • Each command calls a function or opens a link; Next.js and other routers plug in with one option
  • Built on the native <dialog>: focus trap, inert background and Esc for free, no overlay hacks
  • Every colour, radius and timing is a CSS custom property; light and dark follow your page
  • Nothing to install: one CSS file and one small script, or one React component

Features

  • Opens with ⌘K / Ctrl+K or any button you mark; Esc or a click outside closes it
  • Fuzzy search that forgives skipped letters and accents, with the matched letters highlighted
  • Results ranked by how well they match and grouped by section
  • Recently run commands on top, remembered across reloads
  • Commands run a function or follow a link (your router's, if you like)
  • Frosted-glass look in light and dark, themed with CSS custom properties
  • Plain HTML/CSS/JS and React (Next.js ready) builds
  • Zero dependencies, about 8 KB gzipped (script and styles together)

How to use it

Link the stylesheet and the script once, then give it your commands. It builds its own dialog; any element with data-command-palette-open opens it, and so does ⌘K / Ctrl+K:

HTML
<link rel="stylesheet" href="command-palette.css" />
<script src="command-palette.js" defer></script>

<button type="button" data-command-palette-open>
  Search… <kbd data-command-palette-hotkey>⌘K</kbd>
</button>

<script>
  document.addEventListener("DOMContentLoaded", () => {
    const palette = CommandPalette.create({
      items: [
        { id: "home", title: "Home", section: "Navigation", href: "/" },
        { id: "billing", title: "Billing", section: "Navigation", keywords: ["invoices", "plan"], href: "/billing" },
        { id: "theme", title: "Toggle theme", section: "Actions", icon: "🌓", shortcut: ["T"], perform: toggleTheme },
      ],
    });
  });
</script>

create returns { open, close, toggle, setItems, isOpen, destroy }; setItems swaps the commands at any time (load them from your API, say). A <kbd data-command-palette-hotkey> is rewritten to "⌘K" on Apple devices and "Ctrl+K" elsewhere. An icon is text (an emoji) or a DOM node, such as an <svg> from a <template> — it is cloned for every row.

Options:

Option Default What it does
items — The commands (see below)
placeholder "Type a command or search…" Search box placeholder
hotkey "mod+k" mod is ⌘ on Apple devices, Ctrl elsewhere; e.g. "ctrl+shift+p", "/"; false for none
recent true Recently run commands on top; false, or { key, limit } (localStorage key, default 5)
trigger "[data-command-palette-open]" Clicks on anything matching it open the palette; false for none
navigate location.assign How an href is followed
onRun(item) — Called with every command run, before it runs
onOpenChange(open) — Called when it opens or closes
texts English Every word it shows or announces, for translation (see core/texts.ts)
container document.body Where the dialog is added

Ask about this product

Not sure it fits your project? Ask — the answer comes from this page.

Answers are written by AI from this page and can be wrong. The page itself is what counts.

Changelog

  1. 1.0.0First releaseLatest

    Plain HTML/CSS/JS and React builds. ⌘K / Ctrl+K hotkey, fuzzy search with highlights, sections, recent commands, full keyboard and screen-reader support, light and dark.

  2. Fixes and new features land behind the same download, which always serves the latest version.

Reviews

No reviews yet

Used it? Be the first to say how it went.

Write a review

How did it work for you? Reviews appear once we have read them.

Your rating
Never shown. Only used if we need to reach you about your review.
0 / 2000

Your name and review are shown on this page; your email is not. See the terms.