Actions
Command
A searchable list of links and actions, inline or in a dialog, that filters as you type.
| Class name | Type | Description |
|---|---|---|
commandplf:command | Component | The searchable list of actions |
command-dialogplf:command-dialog | Component | A Modal dialog that holds a command palette |
command-searchplf:command-search | Part | The search row |
command-inputplf:command-input | Part | The search field |
command-iconplf:command-icon | Part | An action's SVG icon, or your own in place of the search row's drawn one; an icon class there doesn't need it |
command-clearplf:command-clear | Part | The button that clears the search, which draws an x while empty |
command-listplf:command-list | Part | The scrolling list of groups |
command-groupplf:command-group | Part | A group of actions |
command-headingplf:command-heading | Part | A group's heading |
command-itemsplf:command-items | Part | A group's list of rows |
command-rowplf:command-row | Part | The list item around an action |
command-itemplf:command-item | Part | A link or button action |
command-labelplf:command-label | Part | An action's label |
command-descriptionplf:command-description | Part | Secondary text after the label |
command-shortcutplf:command-shortcut | Part | A key hint at the end of an action |
command-separatorplf:command-separator | Part | A divider between groups |
command-emptyplf:command-empty | Part | The message when nothing matches |
command-footerplf:command-footer | Part | A footer of key hints |
command-keyplf:command-key | Part | A key in the footer |
<div class="command" id="command-default" data-plf-command>
<div class="command-search" hidden>
<input class="command-input" type="text" aria-label="Search commands" placeholder="Search pages or actions…" autocomplete="off" spellcheck="false">
<button class="command-clear" aria-label="Clear search"></button>
</div>
<div class="command-list">
<section class="command-group">
<h3 class="command-heading">Pages</h3>
<ul class="command-items">
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="calendar" data-plf-keywords="dates reporting period">
<span class="icon icon-calendar"></span>
<span class="command-label" data-plf-command-label>Calendar</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="customers" data-plf-keywords="people contacts datatable">
<span class="icon icon-table"></span>
<span class="command-label" data-plf-command-label>Customers</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="analytics" data-plf-keywords="reports revenue insights">
<span class="icon icon-chart-column"></span>
<span class="command-label" data-plf-command-label>Analytics</span>
</a>
</li>
</ul>
</section>
<hr class="command-separator">
<section class="command-group">
<h3 class="command-heading">Actions</h3>
<ul class="command-items">
<li class="command-row">
<button class="command-item" data-plf-command-item="profile" data-plf-keywords="account settings personal">
<span class="icon icon-user"></span>
<span class="command-label" data-plf-command-label>Open profile</span>
<kbd class="command-shortcut" aria-hidden="true">⌘P</kbd>
</button>
</li>
<li class="command-row">
<button class="command-item" disabled data-plf-command-item="billing" data-plf-keywords="invoice payment subscription">
<span class="icon icon-credit-card"></span>
<span class="command-label" data-plf-command-label>Manage billing</span>
</button>
</li>
<li class="command-row">
<button class="command-item" data-plf-command-item="copy" data-plf-keywords="clipboard identifier">
<span class="icon icon-copy"></span>
<span class="command-label" data-plf-command-label>Copy workspace ID</span>
<kbd class="command-shortcut" aria-hidden="true">⌘C</kbd>
</button>
</li>
</ul>
</section>
</div>
<p class="command-empty" data-plf-command-empty hidden>No commands found. Try a page name or keyword.</p>
<div class="command-footer" data-plf-command-help hidden>
<span><kbd class="command-key">↑ ↓</kbd> Navigate · <kbd class="command-key">Enter</kbd> Run</span>
<span><kbd class="command-key">Esc</kbd> Back / clear</span>
</div>
</div>
<script>
const actions = {
profile: () => { /* Open the profile. */ },
copy: () => navigator.clipboard?.writeText('workspace-id'),
};
document.getElementById('command-default').addEventListener('plf:command:select', event => {
actions[event.detail.key]?.();
});
</script><div class="plf:command" id="command-default" data-plf-command>
<div class="plf:command-search" hidden>
<input class="plf:command-input" type="text" aria-label="Search commands" placeholder="Search pages or actions…" autocomplete="off" spellcheck="false">
<button class="plf:command-clear" aria-label="Clear search"></button>
</div>
<div class="plf:command-list">
<section class="plf:command-group">
<h3 class="plf:command-heading">Pages</h3>
<ul class="plf:command-items">
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="calendar" data-plf-keywords="dates reporting period">
<span class="plf:icon plf:icon-calendar"></span>
<span class="plf:command-label" data-plf-command-label>Calendar</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="customers" data-plf-keywords="people contacts datatable">
<span class="plf:icon plf:icon-table"></span>
<span class="plf:command-label" data-plf-command-label>Customers</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="analytics" data-plf-keywords="reports revenue insights">
<span class="plf:icon plf:icon-chart-column"></span>
<span class="plf:command-label" data-plf-command-label>Analytics</span>
</a>
</li>
</ul>
</section>
<hr class="plf:command-separator">
<section class="plf:command-group">
<h3 class="plf:command-heading">Actions</h3>
<ul class="plf:command-items">
<li class="plf:command-row">
<button class="plf:command-item" data-plf-command-item="profile" data-plf-keywords="account settings personal">
<span class="plf:icon plf:icon-user"></span>
<span class="plf:command-label" data-plf-command-label>Open profile</span>
<kbd class="plf:command-shortcut" aria-hidden="true">⌘P</kbd>
</button>
</li>
<li class="plf:command-row">
<button class="plf:command-item" disabled data-plf-command-item="billing" data-plf-keywords="invoice payment subscription">
<span class="plf:icon plf:icon-credit-card"></span>
<span class="plf:command-label" data-plf-command-label>Manage billing</span>
</button>
</li>
<li class="plf:command-row">
<button class="plf:command-item" data-plf-command-item="copy" data-plf-keywords="clipboard identifier">
<span class="plf:icon plf:icon-copy"></span>
<span class="plf:command-label" data-plf-command-label>Copy workspace ID</span>
<kbd class="plf:command-shortcut" aria-hidden="true">⌘C</kbd>
</button>
</li>
</ul>
</section>
</div>
<p class="plf:command-empty" data-plf-command-empty hidden>No commands found. Try a page name or keyword.</p>
<div class="plf:command-footer" data-plf-command-help hidden>
<span><kbd class="plf:command-key">↑ ↓</kbd> Navigate · <kbd class="plf:command-key">Enter</kbd> Run</span>
<span><kbd class="plf:command-key">Esc</kbd> Back / clear</span>
</div>
</div>
<script>
const actions = {
profile: () => { /* Open the profile. */ },
copy: () => navigator.clipboard?.writeText('workspace-id'),
};
document.getElementById('command-default').addEventListener('plf:command:select', event => {
actions[event.detail.key]?.();
});
</script>'use client';
import {
Command, CommandClear, CommandEmpty, CommandFooter, CommandGroup, CommandInput, CommandItem, CommandKey, CommandLabel, CommandList,
CommandSearch, CommandSeparator, CommandShortcut, Icon,
} from '@pelatform/react';
export function Example() {
return (
<Command>
<CommandSearch>
<CommandInput aria-label="Search commands" placeholder="Search pages or actions…" />
<CommandClear />
</CommandSearch>
<CommandList>
<CommandGroup heading="Pages">
<CommandItem value="calendar" href="#" keywords="dates reporting period">
<Icon name="calendar" />
<CommandLabel>Calendar</CommandLabel>
</CommandItem>
<CommandItem value="customers" href="#" keywords="people contacts datatable">
<Icon name="table" />
<CommandLabel>Customers</CommandLabel>
</CommandItem>
<CommandItem value="analytics" href="#" keywords="reports revenue insights">
<Icon name="chart-column" />
<CommandLabel>Analytics</CommandLabel>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Actions">
<CommandItem value="profile" keywords="account settings personal" onSelect={() => { /* Open the profile. */ }}>
<Icon name="user" />
<CommandLabel>Open profile</CommandLabel>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem value="billing" disabled keywords="invoice payment subscription">
<Icon name="credit-card" />
<CommandLabel>Manage billing</CommandLabel>
</CommandItem>
<CommandItem value="copy" keywords="clipboard identifier" onSelect={() => navigator.clipboard?.writeText('workspace-id')}>
<Icon name="copy" />
<CommandLabel>Copy workspace ID</CommandLabel>
<CommandShortcut>⌘C</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
<CommandEmpty>No commands found. Try a page name or keyword.</CommandEmpty>
<CommandFooter>
<span><CommandKey>↑ ↓</CommandKey> Navigate · <CommandKey>Enter</CommandKey> Run</span>
<span><CommandKey>Esc</CommandKey> Back / clear</span>
</CommandFooter>
</Command>
);
}'use client';
import {
Command, CommandClear, CommandEmpty, CommandFooter, CommandGroup, CommandInput, CommandItem, CommandKey, CommandLabel, CommandList,
CommandSearch, CommandSeparator, CommandShortcut, Icon,
} from '@pelatform/react/prefixed';
export function Example() {
return (
<Command>
<CommandSearch>
<CommandInput aria-label="Search commands" placeholder="Search pages or actions…" />
<CommandClear />
</CommandSearch>
<CommandList>
<CommandGroup heading="Pages">
<CommandItem value="calendar" href="#" keywords="dates reporting period">
<Icon name="calendar" />
<CommandLabel>Calendar</CommandLabel>
</CommandItem>
<CommandItem value="customers" href="#" keywords="people contacts datatable">
<Icon name="table" />
<CommandLabel>Customers</CommandLabel>
</CommandItem>
<CommandItem value="analytics" href="#" keywords="reports revenue insights">
<Icon name="chart-column" />
<CommandLabel>Analytics</CommandLabel>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Actions">
<CommandItem value="profile" keywords="account settings personal" onSelect={() => { /* Open the profile. */ }}>
<Icon name="user" />
<CommandLabel>Open profile</CommandLabel>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem value="billing" disabled keywords="invoice payment subscription">
<Icon name="credit-card" />
<CommandLabel>Manage billing</CommandLabel>
</CommandItem>
<CommandItem value="copy" keywords="clipboard identifier" onSelect={() => navigator.clipboard?.writeText('workspace-id')}>
<Icon name="copy" />
<CommandLabel>Copy workspace ID</CommandLabel>
<CommandShortcut>⌘C</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
<CommandEmpty>No commands found. Try a page name or keyword.</CommandEmpty>
<CommandFooter>
<span><CommandKey>↑ ↓</CommandKey> Navigate · <CommandKey>Enter</CommandKey> Run</span>
<span><CommandKey>Esc</CommandKey> Back / clear</span>
</CommandFooter>
</Command>
);
}Links navigate as usual; the script runs button actions from plf:command:select by their key.
Descriptions
A description is not searched, so repeat its words in data-plf-keywords.
Pages
Sections
No matching pages or sections.
<div class="command" data-plf-command>
<div class="command-search" hidden>
<input class="command-input" type="text" aria-label="Search documentation" placeholder="Search pages and sections…" autocomplete="off" spellcheck="false">
</div>
<div class="command-list">
<section class="command-group">
<h3 class="command-heading">Pages</h3>
<ul class="command-items">
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="installation" data-plf-keywords="Getting started setup">
<span class="command-label" data-plf-command-label>Installation</span>
<span class="command-description">Getting started</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="tokens" data-plf-keywords="Foundations colors dark mode">
<span class="command-label" data-plf-command-label>Tokens and themes</span>
<span class="command-description">Foundations</span>
</a>
</li>
</ul>
</section>
<section class="command-group">
<h3 class="command-heading">Sections</h3>
<ul class="command-items">
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="button-accessibility" data-plf-keywords="Button keyboard focus">
<span class="command-label" data-plf-command-label>Accessibility</span>
<span class="command-description">Button</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="tabs-keyboard" data-plf-keywords="Tabs arrow keys">
<span class="command-label" data-plf-command-label>Keyboard</span>
<span class="command-description">Tabs</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="date-time-states" data-plf-keywords="Date & Time Picker with seconds and bounds disabled invalid">
<span class="command-label" data-plf-command-label>States and accessibility</span>
<span class="command-description">Date & Time Picker with seconds and bounds</span>
</a>
</li>
</ul>
</section>
</div>
<p class="command-empty" data-plf-command-empty hidden>No matching pages or sections.</p>
</div><div class="plf:command" data-plf-command>
<div class="plf:command-search" hidden>
<input class="plf:command-input" type="text" aria-label="Search documentation" placeholder="Search pages and sections…" autocomplete="off" spellcheck="false">
</div>
<div class="plf:command-list">
<section class="plf:command-group">
<h3 class="plf:command-heading">Pages</h3>
<ul class="plf:command-items">
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="installation" data-plf-keywords="Getting started setup">
<span class="plf:command-label" data-plf-command-label>Installation</span>
<span class="plf:command-description">Getting started</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="tokens" data-plf-keywords="Foundations colors dark mode">
<span class="plf:command-label" data-plf-command-label>Tokens and themes</span>
<span class="plf:command-description">Foundations</span>
</a>
</li>
</ul>
</section>
<section class="plf:command-group">
<h3 class="plf:command-heading">Sections</h3>
<ul class="plf:command-items">
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="button-accessibility" data-plf-keywords="Button keyboard focus">
<span class="plf:command-label" data-plf-command-label>Accessibility</span>
<span class="plf:command-description">Button</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="tabs-keyboard" data-plf-keywords="Tabs arrow keys">
<span class="plf:command-label" data-plf-command-label>Keyboard</span>
<span class="plf:command-description">Tabs</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="date-time-states" data-plf-keywords="Date & Time Picker with seconds and bounds disabled invalid">
<span class="plf:command-label" data-plf-command-label>States and accessibility</span>
<span class="plf:command-description">Date & Time Picker with seconds and bounds</span>
</a>
</li>
</ul>
</section>
</div>
<p class="plf:command-empty" data-plf-command-empty hidden>No matching pages or sections.</p>
</div>import { Command, CommandDescription, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandLabel, CommandList, CommandSearch } from '@pelatform/react';
export function Example() {
return (
<Command>
<CommandSearch>
<CommandInput aria-label="Search documentation" placeholder="Search pages and sections…" />
</CommandSearch>
<CommandList>
<CommandGroup heading="Pages">
<CommandItem value="installation" href="#" keywords="Getting started setup">
<CommandLabel>Installation</CommandLabel>
<CommandDescription>Getting started</CommandDescription>
</CommandItem>
<CommandItem value="tokens" href="#" keywords="Foundations colors dark mode">
<CommandLabel>Tokens and themes</CommandLabel>
<CommandDescription>Foundations</CommandDescription>
</CommandItem>
</CommandGroup>
<CommandGroup heading="Sections">
<CommandItem value="button-accessibility" href="#" keywords="Button keyboard focus">
<CommandLabel>Accessibility</CommandLabel>
<CommandDescription>Button</CommandDescription>
</CommandItem>
<CommandItem value="tabs-keyboard" href="#" keywords="Tabs arrow keys">
<CommandLabel>Keyboard</CommandLabel>
<CommandDescription>Tabs</CommandDescription>
</CommandItem>
<CommandItem value="date-time-states" href="#" keywords="Date & Time Picker with seconds and bounds disabled invalid">
<CommandLabel>States and accessibility</CommandLabel>
<CommandDescription>Date & Time Picker with seconds and bounds</CommandDescription>
</CommandItem>
</CommandGroup>
</CommandList>
<CommandEmpty>No matching pages or sections.</CommandEmpty>
</Command>
);
}import { Command, CommandDescription, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandLabel, CommandList, CommandSearch } from '@pelatform/react/prefixed';
export function Example() {
return (
<Command>
<CommandSearch>
<CommandInput aria-label="Search documentation" placeholder="Search pages and sections…" />
</CommandSearch>
<CommandList>
<CommandGroup heading="Pages">
<CommandItem value="installation" href="#" keywords="Getting started setup">
<CommandLabel>Installation</CommandLabel>
<CommandDescription>Getting started</CommandDescription>
</CommandItem>
<CommandItem value="tokens" href="#" keywords="Foundations colors dark mode">
<CommandLabel>Tokens and themes</CommandLabel>
<CommandDescription>Foundations</CommandDescription>
</CommandItem>
</CommandGroup>
<CommandGroup heading="Sections">
<CommandItem value="button-accessibility" href="#" keywords="Button keyboard focus">
<CommandLabel>Accessibility</CommandLabel>
<CommandDescription>Button</CommandDescription>
</CommandItem>
<CommandItem value="tabs-keyboard" href="#" keywords="Tabs arrow keys">
<CommandLabel>Keyboard</CommandLabel>
<CommandDescription>Tabs</CommandDescription>
</CommandItem>
<CommandItem value="date-time-states" href="#" keywords="Date & Time Picker with seconds and bounds disabled invalid">
<CommandLabel>States and accessibility</CommandLabel>
<CommandDescription>Date & Time Picker with seconds and bounds</CommandDescription>
</CommandItem>
</CommandGroup>
</CommandList>
<CommandEmpty>No matching pages or sections.</CommandEmpty>
</Command>
);
}Dialog
In the Modal, give the field autofocus and keep a close button. An action closes the dialog, and aria-keyshortcuts on the open button opens it from the keyboard outside text fields.
<div class="flex flex-wrap items-center gap-4">
<button class="btn btn-outline" data-plf-trigger="modal:open" data-plf-target="command-dialog" aria-keyshortcuts="Control+K Meta+K">Open command palette</button>
</div>
<dialog class="modal command-dialog" data-plf-modal id="command-dialog" aria-label="Command palette">
<div class="command" data-plf-command>
<div class="command-search" hidden>
<input class="command-input" type="text" aria-label="Search commands" placeholder="Search pages or actions…" autocomplete="off" spellcheck="false" autofocus>
<button class="command-clear" aria-label="Clear search"></button>
</div>
<div class="command-list">
<section class="command-group">
<h3 class="command-heading">Pages</h3>
<ul class="command-items">
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="calendar" data-plf-keywords="dates reporting period">
<span class="icon icon-calendar"></span>
<span class="command-label" data-plf-command-label>Calendar</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="customers" data-plf-keywords="people contacts datatable">
<span class="icon icon-table"></span>
<span class="command-label" data-plf-command-label>Customers</span>
</a>
</li>
<li class="command-row">
<a class="command-item" href="#" data-plf-command-item="analytics" data-plf-keywords="reports revenue insights">
<span class="icon icon-chart-column"></span>
<span class="command-label" data-plf-command-label>Analytics</span>
</a>
</li>
</ul>
</section>
<hr class="command-separator">
<section class="command-group">
<h3 class="command-heading">Actions</h3>
<ul class="command-items">
<li class="command-row">
<button class="command-item" data-plf-command-item="profile" data-plf-keywords="account settings personal">
<span class="icon icon-user"></span>
<span class="command-label" data-plf-command-label>Open profile</span>
<kbd class="command-shortcut" aria-hidden="true">⌘P</kbd>
</button>
</li>
<li class="command-row">
<button class="command-item" disabled data-plf-command-item="billing" data-plf-keywords="invoice payment subscription">
<span class="icon icon-credit-card"></span>
<span class="command-label" data-plf-command-label>Manage billing</span>
</button>
</li>
<li class="command-row">
<button class="command-item" data-plf-command-item="copy" data-plf-keywords="clipboard identifier">
<span class="icon icon-copy"></span>
<span class="command-label" data-plf-command-label>Copy workspace ID</span>
<kbd class="command-shortcut" aria-hidden="true">⌘C</kbd>
</button>
</li>
</ul>
</section>
</div>
<p class="command-empty" data-plf-command-empty hidden>No commands found. Try a page name or keyword.</p>
<div class="command-footer" data-plf-command-help hidden>
<span><kbd class="command-key">↑ ↓</kbd> Navigate · <kbd class="command-key">Enter</kbd> Run</span>
<button class="modal-close" data-plf-trigger="modal:close" aria-label="Close command palette">Close</button>
</div>
</div>
</dialog><div class="plf:flex plf:flex-wrap plf:items-center plf:gap-4">
<button class="plf:btn plf:btn-outline" data-plf-trigger="modal:open" data-plf-target="command-dialog" aria-keyshortcuts="Control+K Meta+K">Open command palette</button>
</div>
<dialog class="plf:modal plf:command-dialog" data-plf-modal id="command-dialog" aria-label="Command palette">
<div class="plf:command" data-plf-command>
<div class="plf:command-search" hidden>
<input class="plf:command-input" type="text" aria-label="Search commands" placeholder="Search pages or actions…" autocomplete="off" spellcheck="false" autofocus>
<button class="plf:command-clear" aria-label="Clear search"></button>
</div>
<div class="plf:command-list">
<section class="plf:command-group">
<h3 class="plf:command-heading">Pages</h3>
<ul class="plf:command-items">
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="calendar" data-plf-keywords="dates reporting period">
<span class="plf:icon plf:icon-calendar"></span>
<span class="plf:command-label" data-plf-command-label>Calendar</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="customers" data-plf-keywords="people contacts datatable">
<span class="plf:icon plf:icon-table"></span>
<span class="plf:command-label" data-plf-command-label>Customers</span>
</a>
</li>
<li class="plf:command-row">
<a class="plf:command-item" href="#" data-plf-command-item="analytics" data-plf-keywords="reports revenue insights">
<span class="plf:icon plf:icon-chart-column"></span>
<span class="plf:command-label" data-plf-command-label>Analytics</span>
</a>
</li>
</ul>
</section>
<hr class="plf:command-separator">
<section class="plf:command-group">
<h3 class="plf:command-heading">Actions</h3>
<ul class="plf:command-items">
<li class="plf:command-row">
<button class="plf:command-item" data-plf-command-item="profile" data-plf-keywords="account settings personal">
<span class="plf:icon plf:icon-user"></span>
<span class="plf:command-label" data-plf-command-label>Open profile</span>
<kbd class="plf:command-shortcut" aria-hidden="true">⌘P</kbd>
</button>
</li>
<li class="plf:command-row">
<button class="plf:command-item" disabled data-plf-command-item="billing" data-plf-keywords="invoice payment subscription">
<span class="plf:icon plf:icon-credit-card"></span>
<span class="plf:command-label" data-plf-command-label>Manage billing</span>
</button>
</li>
<li class="plf:command-row">
<button class="plf:command-item" data-plf-command-item="copy" data-plf-keywords="clipboard identifier">
<span class="plf:icon plf:icon-copy"></span>
<span class="plf:command-label" data-plf-command-label>Copy workspace ID</span>
<kbd class="plf:command-shortcut" aria-hidden="true">⌘C</kbd>
</button>
</li>
</ul>
</section>
</div>
<p class="plf:command-empty" data-plf-command-empty hidden>No commands found. Try a page name or keyword.</p>
<div class="plf:command-footer" data-plf-command-help hidden>
<span><kbd class="plf:command-key">↑ ↓</kbd> Navigate · <kbd class="plf:command-key">Enter</kbd> Run</span>
<button class="plf:modal-close" data-plf-trigger="modal:close" aria-label="Close command palette">Close</button>
</div>
</div>
</dialog>'use client';
import { useEffect, useState } from 'react';
import {
Button, Command, CommandClear, CommandDialog, CommandEmpty, CommandFooter, CommandGroup, CommandInput, CommandItem, CommandKey,
CommandLabel, CommandList, CommandSearch, CommandSeparator, CommandShortcut, Icon, ModalClose,
} from '@pelatform/react';
export function Example() {
const [open, setOpen] = useState(false);
// As the button's aria-keyshortcuts says, Control+K and Command+K open the closed palette outside text fields.
useEffect(() => {
if (open) return;
const shortcut = (event: KeyboardEvent) => {
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== 'k' || (event.target as Element).closest('input, textarea, select, [contenteditable]')) return;
event.preventDefault();
setOpen(true);
};
document.addEventListener('keydown', shortcut);
return () => document.removeEventListener('keydown', shortcut);
}, [open]);
return (
<>
<div className="flex flex-wrap items-center gap-4">
<Button variant="outline" aria-keyshortcuts="Control+K Meta+K" onClick={() => setOpen(true)}>Open command palette</Button>
</div>
<CommandDialog open={open} onOpenChange={setOpen} aria-label="Command palette">
<Command>
<CommandSearch>
<CommandInput aria-label="Search commands" placeholder="Search pages or actions…" autoFocus />
<CommandClear />
</CommandSearch>
<CommandList>
<CommandGroup heading="Pages">
<CommandItem value="calendar" href="#" keywords="dates reporting period">
<Icon name="calendar" />
<CommandLabel>Calendar</CommandLabel>
</CommandItem>
<CommandItem value="customers" href="#" keywords="people contacts datatable">
<Icon name="table" />
<CommandLabel>Customers</CommandLabel>
</CommandItem>
<CommandItem value="analytics" href="#" keywords="reports revenue insights">
<Icon name="chart-column" />
<CommandLabel>Analytics</CommandLabel>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Actions">
<CommandItem value="profile" keywords="account settings personal">
<Icon name="user" />
<CommandLabel>Open profile</CommandLabel>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem value="billing" disabled keywords="invoice payment subscription">
<Icon name="credit-card" />
<CommandLabel>Manage billing</CommandLabel>
</CommandItem>
<CommandItem value="copy" keywords="clipboard identifier">
<Icon name="copy" />
<CommandLabel>Copy workspace ID</CommandLabel>
<CommandShortcut>⌘C</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
<CommandEmpty>No commands found. Try a page name or keyword.</CommandEmpty>
<CommandFooter>
<span><CommandKey>↑ ↓</CommandKey> Navigate · <CommandKey>Enter</CommandKey> Run</span>
<ModalClose aria-label="Close command palette">Close</ModalClose>
</CommandFooter>
</Command>
</CommandDialog>
</>
);
}'use client';
import { useEffect, useState } from 'react';
import {
Button, Command, CommandClear, CommandDialog, CommandEmpty, CommandFooter, CommandGroup, CommandInput, CommandItem, CommandKey,
CommandLabel, CommandList, CommandSearch, CommandSeparator, CommandShortcut, Icon, ModalClose,
} from '@pelatform/react/prefixed';
export function Example() {
const [open, setOpen] = useState(false);
// As the button's aria-keyshortcuts says, Control+K and Command+K open the closed palette outside text fields.
useEffect(() => {
if (open) return;
const shortcut = (event: KeyboardEvent) => {
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== 'k' || (event.target as Element).closest('input, textarea, select, [contenteditable]')) return;
event.preventDefault();
setOpen(true);
};
document.addEventListener('keydown', shortcut);
return () => document.removeEventListener('keydown', shortcut);
}, [open]);
return (
<>
<div className="plf:flex plf:flex-wrap plf:items-center plf:gap-4">
<Button variant="outline" aria-keyshortcuts="Control+K Meta+K" onClick={() => setOpen(true)}>Open command palette</Button>
</div>
<CommandDialog open={open} onOpenChange={setOpen} aria-label="Command palette">
<Command>
<CommandSearch>
<CommandInput aria-label="Search commands" placeholder="Search pages or actions…" autoFocus />
<CommandClear />
</CommandSearch>
<CommandList>
<CommandGroup heading="Pages">
<CommandItem value="calendar" href="#" keywords="dates reporting period">
<Icon name="calendar" />
<CommandLabel>Calendar</CommandLabel>
</CommandItem>
<CommandItem value="customers" href="#" keywords="people contacts datatable">
<Icon name="table" />
<CommandLabel>Customers</CommandLabel>
</CommandItem>
<CommandItem value="analytics" href="#" keywords="reports revenue insights">
<Icon name="chart-column" />
<CommandLabel>Analytics</CommandLabel>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Actions">
<CommandItem value="profile" keywords="account settings personal">
<Icon name="user" />
<CommandLabel>Open profile</CommandLabel>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem value="billing" disabled keywords="invoice payment subscription">
<Icon name="credit-card" />
<CommandLabel>Manage billing</CommandLabel>
</CommandItem>
<CommandItem value="copy" keywords="clipboard identifier">
<Icon name="copy" />
<CommandLabel>Copy workspace ID</CommandLabel>
<CommandShortcut>⌘C</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
<CommandEmpty>No commands found. Try a page name or keyword.</CommandEmpty>
<CommandFooter>
<span><CommandKey>↑ ↓</CommandKey> Navigate · <CommandKey>Enter</CommandKey> Run</span>
<ModalClose aria-label="Close command palette">Close</ModalClose>
</CommandFooter>
</Command>
</CommandDialog>
</>
);
}JavaScript
Command needs JavaScript to search. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.
<link rel="stylesheet" href="pelatform-ui.min.css">
<link rel="stylesheet" href="icons/icons.min.css">
<script src="pelatform-ui.min.js" defer></script><link rel="stylesheet" href="core/pelatform-ui-core.min.css">
<link rel="stylesheet" href="components/button.min.css">
<link rel="stylesheet" href="components/modal.min.css">
<link rel="stylesheet" href="components/command.min.css">
<link rel="stylesheet" href="icons/icons.min.css">
<script src="core/pelatform-ui-core.min.js" defer></script>
<script src="components/modal.min.js" defer></script>
<script src="components/command.min.js" defer></script>
<script>document.addEventListener('DOMContentLoaded', () => PLF.init());</script><link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<link rel="stylesheet" href="icons/icons.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script><link rel="stylesheet" href="core/pelatform-ui-core.prefixed.min.css">
<link rel="stylesheet" href="components/button.prefixed.min.css">
<link rel="stylesheet" href="components/modal.prefixed.min.css">
<link rel="stylesheet" href="components/command.prefixed.min.css">
<link rel="stylesheet" href="icons/icons.prefixed.min.css">
<script src="core/pelatform-ui-core.min.js" defer></script>
<script src="components/modal.min.js" defer></script>
<script src="components/command.min.js" defer></script>
<script>document.addEventListener('DOMContentLoaded', () => PLF.init());</script>| Attribute | Purpose |
|---|---|
data-plf-command |
Marks the container |
data-plf-command-controls |
Optional: the search row, which is the parent of the Command’s one <input>; authored hidden |
data-plf-command-clear |
Optional: the clear button, which is the search row’s one <button> |
data-plf-command-list |
Optional: the list, which is the child that holds the actions |
data-plf-command-group |
Optional: a group; groups are the list’s children other than <hr>, each named by its heading |
data-plf-command-item |
The link or button; its value is a key, unique in the Command |
data-plf-command-label |
The action’s label; exactly one per action |
data-plf-keywords |
Optional: more words to search |
data-plf-command-empty |
The command-empty message, authored hidden |
data-plf-command-help |
Optional: a command-footer with command-key labels, authored hidden |
data-plf-results-label, data-plf-available-label |
On the container, the status words; Results and Available by default |
The script shows the search row and the footer, adds a polite live region that announces the counts, hides rows, groups and separators without a match, and marks the active action with data-plf-command-active.
Methods
| Method | Behavior |
|---|---|
PLF. |
Returns the instance, creating it for valid markup. The options resultsLabel and availableLabel set the status words |
PLF. |
Returns the instance or null |
instance. |
Searches for value. Returns false when unchanged or canceled |
instance. |
Focuses that action. Returns false when it is unavailable or already focused |
instance. |
Runs that action as a click does. Returns false when it is unavailable or canceled |
instance. |
Returns { query, activeKey, totalCount, matchingCount, availableCount } |
instance. |
Removes listeners and restores what the script changed |
| Event | When |
|---|---|
plf: |
Before the search changes; cancelable |
plf: |
After the search changes |
plf: |
Before an action runs; cancelable |
plf: |
As an action runs, before its click or navigation; in a Modal it then closes the dialog, unless a handler calls preventDefault |
Each event’s detail:
| Property | Events | Value |
|---|---|---|
instance |
All | The Command instance |
reason |
All | api, trigger or keyboard |
trigger |
All | The field, the clear button or the chosen action, or null from setQuery |
previousState |
before-change, change |
The state before the change, shaped like getState |
state |
before-change, change |
The state after the change |
item |
before-select, select |
The action’s link or button |
key |
before-select, select |
The action’s key |
query |
before-select, select |
The search text |
| Key | Action |
|---|---|
| Down Arrow, Up Arrow | From the field, focus the first or last action; on an action, move to the next or previous one |
| Home, End | On an action, focus the first or last one |
| Enter | Runs the active action |
| Space | On a button action, runs it |
| Escape | On an action, returns to the field; in the field, clears the search. In a Modal, closes the dialog |
| Tab, Shift+Tab | Move between the field, the clear button and the active action |
React
Command from @pelatform/react renders this search with its status: typing filters the items by their label and keywords, and the keys move between the field and the items, as the script’s do. Each part is a component of its own.
| Prop | Values | Default |
|---|---|---|
resultsLabel, availableLabel |
The status words before the numbers of matches and of items that can run | Results, Available |
open |
On CommandDialog, true while the palette is open |
Required |
onOpenChange |
On CommandDialog, (open, reason), called when it asks to close: trigger (a chosen item or a ModalClose), keyboard (Escape) or backdrop; keep open to stay open |
None |
closeOnBackdrop |
On CommandDialog, true closes on a click outside the palette |
false |
heading |
On CommandGroup, the group’s heading, which names it |
None |
level |
On CommandGroup, the heading’s level, 2 to 6 |
3 |
value |
On CommandItem, its key, unique in the Command |
Required |
keywords |
On CommandItem, more words to search, such as its description’s |
None |
onSelect |
On CommandItem, (event), called when the item is chosen by a click or Enter; in a CommandDialog, the dialog then asks to close with trigger unless it calls event. |
None |
aria-label |
On CommandClear, the button’s name |
Clear search |
The parts:
| Part | Element |
|---|---|
CommandDialog |
A Modal with command-dialog around the Command, which takes Modal’s parts, such as ModalClose |
CommandSearch |
A div with command-search |
CommandInput |
An input with command-input, whose value the Command keeps; its onChange hears the search |
CommandClear |
A button with command-clear, shown while there is a search |
CommandList |
A div with command-list, a child of Command |
CommandGroup |
A section with command-group, its heading and a command-items list, a child of CommandList |
CommandItem |
A button with command-item in a command-row, or a link with href, a child of CommandGroup |
CommandLabel |
A span with command-label, the item’s searched text |
CommandDescription |
A span with command-description |
CommandShortcut |
A kbd with command-shortcut, hidden from assistive technologies |
CommandSeparator |
An hr with command-separator |
CommandEmpty |
A p with command-empty, shown while nothing matches |
CommandFooter |
A div with command-footer |
CommandKey |
A kbd with command-key |
The other props are the element’s own, className and ref included. CommandDialog doesn’t bind aria-keyshortcuts, so the Dialog example opens it on Control+K and Command+K itself.
| Variable | Default |
|---|---|
--plf-command-bg, --plf-command-color |
Elevated surface and text |
--plf-command-border |
--plf-color-border-subtle |
--plf-command-divider-color |
--plf-color-border-subtle |
--plf-command-radius |
Extra large radius (12px) |
--plf-command-icon-color, --plf-command-heading-color |
Muted text |
--plf-command-item-active-bg |
Muted surface |
--plf-command-item-height |
40px, a minimum |
--plf-command-list-max-height |
20rem |
--plf-command-dialog-width |
32rem |