Reference

CommandPalette

A dialog of everything a reader can do or go to, filtered as they type: the arrow keys go through what matches, Enter runs it (on select) and closes. open: is the state that shows it.

CommandPalette(open: State, label: String, placeholder: String) { … }

Since 6.2.0

label

placeholder

Nothing run yet

Commands

Reference
Recipes
New file
Copy link
Switch theme

Example

wf

state palette = false state said = "Nothing run yet" Button("Search commands…") { on click { palette = true } } Text(said).muted.sm CommandPalette(open: palette, label: "Commands", placeholder: "Type a command or a page") { CommandPalette.Group("Pages") { CommandPalette.Item("Reference", icon: "list") { on select { navigate("/reference") } } CommandPalette.Item("Recipes", icon: "book") { on select { navigate("/recipes") } } } CommandPalette.Group("Actions") { CommandPalette.Item("New file", icon: "file-plus", shortcut: "mod+n") { on select { said = "New file" } } CommandPalette.Item("Copy link", icon: "copy", shortcut: "mod+shift+c") { on select { said = "Link copied" } } CommandPalette.Item("Switch theme", icon: "moon") { on select { said = "Theme switched" } } } }

Opened from anywhere with mod+k

wf

state palette = false on key("mod+k") { palette = true } Text { Text("Press ") Kbd("mod+k") Text(" to open the palette") } CommandPalette(open: palette) { CommandPalette.Group("Go to") { CommandPalette.Item("Learn") { on select { navigate("/learn") } } } }

Props

Props of CommandPalette
PropTypeUnsetMeaning

open:

State (required)

—

A Bool state that shows it (a modal), written false when it closes — Escape, a press outside, a choice

label:

String

Commands

Its title, and the name of its field and its list

placeholder:

String

Type a command or search…

Shown in the empty field

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

No flags of its own.

Events

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Parts

The parts of CommandPalette are written under its name, inside it. Each is described here, with what it takes.

CommandPalette.Group

Items under a heading.

CommandPalette.Group(_ title: String) { … }
Props of CommandPalette.Group
PropTypeUnsetMeaning

title

String (positional)

—

Its heading, and the group's accessible name

CommandPalette.Item

One thing to do or go to; on select is what it does.

CommandPalette.Item(_ label: String, icon: String, shortcut: String) { … }
Props of CommandPalette.Item
PropTypeUnsetMeaning

label

String (positional)

—

Its words, which the typing matches

icon:

String

none

The name of a built-in icon, drawn before its words

shortcut:

String

none

Its keys, shown at its end as this system writes them (⌘H); only shown — the key is not bound

Events of CommandPalette.Item
EventSendsMeaning
on select—

Drawn for it

What CommandPalette draws itself, by the class a stylesheet can select. They are not written.

Drawn for it
PartClassMeaning

CommandPalette.List

—

What matches.

Renders with the class wf-command-palette, stable across releases, so a stylesheet may target it.