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
Example
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
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
| Prop | Type | Unset | Meaning |
|---|---|---|---|
open: | State (required) | — | A Bool state that shows it (a modal), written |
label: | String |
| Its title, and the name of its field and its list |
placeholder: | String |
| 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) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
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) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
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 ( |
| Event | Sends | Meaning |
|---|---|---|
on select | — |
Drawn for it
What CommandPalette draws itself, by the class a stylesheet can select. They are not written.
| Part | Class | Meaning |
|---|---|---|
CommandPalette.List | — | What matches. |
Renders with the class wf-command-palette, stable across releases, so a stylesheet may target it.