Actions
Command
A list of actions with a search box on top that filters it as the user types, for command menus and quick navigation. tk:command shows the list in the page; tk:command.modal puts it in a modal opened by a button or a keyboard shortcut, as a command palette.
Each item is a tk:listbox.item. Selecting it clicks it, so what it does is written on the item itself (wire:click, x-on:click).
Nothing to show
A bordered box with a search box over the three items. Typing inv leaves New invoice and Invite member, with the first one highlighted; Enter, Tab or a click selects it, which runs its wire:click. The search box keeps its text after a selection.
As a command palette #
Renders a "Search" button with the shortcut hint, "⌘K" on macOS and "Ctrl K" elsewhere. The button, or that shortcut anywhere on the page, opens a modal with the search box focused. Selecting an item runs its action and closes the modal; Escape closes it too. The items go in the content slot, since the default slot is the trigger.
Nothing to show
Your own trigger #
The default slot replaces the "Search" button; clicking anything in it opens the modal, unless it holds a disabled button. With :close-on-select="false" the modal stays open after each selection, so the user can pin several pages before pressing Escape. The name lets other code open it: tallkit.modal('palette').show() in JavaScript, or $this->modal('palette')->show() in the Livewire component that renders it.
Nothing to show
Rendering from data #
Each item's label is what the search matches. After a Livewire update that changes the items, the list is read again and the current search is applied to it.
Nothing to show
Items from an array #
items renders items after the slot: a string is a label, an array holds the item's props. A disabled item stays visible but cannot be selected.
-
Open
-
In progress
-
Done
-
Archived
Nothing to show
Sizes #
size scales the search box, the items, the rounding and the height of the list.
-
Copy
-
Paste
-
Duplicate
-
Copy
-
Paste
-
Duplicate
-
Copy
-
Paste
-
Duplicate
Nothing to show
Search options #
hide-empty shows nothing until the user types, no-records changes the empty message and clear-on-select empties the search box after a selection.
-
Brazil
-
Portugal
-
Spain
-
France
-
Germany
-
Apple
-
Banana
-
Cherry
-
Grape
Nothing to show
Without search #
searchable set to false removes the search box. The list takes focus itself; arrow keys, Home, End and Space work on it.
-
Newest first
-
Oldest first
-
Name
Nothing to show
A shortcut on your own trigger #
With your own trigger, give it the same kbd as the shortcut to show the keys: ⌘/ on a Mac, Ctrl / elsewhere.
Nothing to show
Events #
searched, highlighted and selected are dispatched on the command itself; listen on the tag with x-on:.
-
Archive
-
Mark as unread
-
Delete
- Query
- Highlighted
- Selected
Nothing to show
Customization #
Prefixed attributes reach the parts: trigger: the Search button, search: the search box, no-records: the empty message and modal: the dialog.
Nothing to show
Reference
tk:command
└── tk:listbox.item
tk:command.modal
├── trigger (default slot)
└── tk:listbox.item (content slot)
tk:command
| Prop | Type | Default | Description |
|---|---|---|---|
size |
string | md |
xs, sm, md, lg, xl, 2xl or 3xl. Sizes the search box, the items, the rounding and the height of the list. |
items |
array | null |
Items rendered after the ones in the slot. A string is an item's label; an array holds the item's attributes (label, icon, disabled...). |
label |
string | null |
The accessible name of the list, translated. |
searchable |
bool | true |
false removes the search box; the list then takes focus itself. |
noRecords |
string | bool | No records found |
The message shown, translated, when the search finds nothing. false removes it. |
hideEmpty |
bool | false |
Shows no item until the user types. The no-records message is then never shown. |
clearOnSelect |
bool | false |
Empties the search box after an item is selected. |
fuseOptions |
array | null |
Options merged into the Fuse.js search (by default threshold 0.1, ignoreLocation and ignoreDiacritics). autoHighlight: false stops highlighting the first match; tabSelects: false stops Tab from selecting. |
color |
string | null |
The color of the list's focus ring, seen when the list itself has focus (searchable off). |
Slots
| Slot | Description |
|---|---|
| default | tk:listbox.item tags. They come before the ones from items. |
search |
Replaces the search box. A tk:input placed here still filters the list and drives it with the arrow keys. |
empty |
Replaces the message shown when the search finds nothing. |
Events
| Event | Detail | When |
|---|---|---|
ready |
The command was set up, after its first filtering. | |
searched |
{ query }, the text of the search box |
The user typed in the search box, before the list is filtered. |
filtered |
{ list, items, filteredItems } |
The list was filtered: on load, when the search box gets focus and after typing. Each item is { title, el, li }. |
highlighted |
{ index, item } |
The highlighted item changed. index is its position among the visible items. |
selected |
{ index, item, button } |
An item was selected, right after its click ran. |
Prefixes
| Prefix | Goes to |
|---|---|
search: |
The search box, a tk:input (search:placeholder). |
items: |
The list (role="listbox"). |
item: |
Each item coming from items. |
no-records: |
The message shown when nothing is found. |
tk:command.modal
| Prop | Type | Default | Description |
|---|---|---|---|
name |
string | generated | The modal's name, to open or close it from elsewhere. |
size |
string | md |
Sizes the trigger button and the command inside. |
shortcut |
string | null |
A key combination that opens the modal from anywhere on the page, written as Alpine key modifiers: mod.k, ctrl.k, meta.k, slash. mod is ⌘ on Apple platforms and Ctrl elsewhere. The default trigger shows it as a tk:kbd hint, in the keys of the user's platform; trigger:kbd replaces the hint, and trigger:kbd="" hides it. |
focusOnOpen |
bool | true |
Moves focus to the search box when the modal opens. false leaves it on the dialog. |
closeOnSelect |
bool | true |
Closes the modal after an item is selected. |
The other attributes, and the tk:command props, go to the tk:command inside.
Slots
| Slot | Description |
|---|---|
| default | The trigger, in place of the "Search" button. |
content |
tk:listbox.item tags. |
search, empty |
As on tk:command. |
Prefixes
| Prefix | Goes to |
|---|---|
trigger: |
The default "Search" button. |
modal: |
The tk:modal, a dialog, and its props (modal:backdrop). |
tk:listbox.item
Takes the element props (label, icon, badge...) and disabled, which keeps the item in the list but out of reach of the keyboard and the pointer.
Slots
| Slot | Description |
|---|---|
| default | The item content, in place of label. |
Events
Events are dispatched on the command's root, the element the tag's attributes go to, and do not bubble: listen on the tag itself. The same holds for tk:command.modal, whose attributes go to the command inside.
On tk:command.modal, an x-on:selected of your own replaces the one that closes the modal: call close() in it to keep that (x-on:selected="close(); ..."). The modal's opened and closed events are heard only through the modal: prefix (modal:x-on:closed), and a modal:x-on:opened replaces the one that focuses the search box.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
On tk:command, classes and attributes go to the bordered box around the search box and the list. On tk:command.modal they go to that same box inside the modal, which is w-md wide unless a width class is given. To reach another element, prefix the attribute (listed in the Reference above).
tk:command.modal also takes the prefixes of tk:command.
Nothing to show
Accessibility
Follows the WAI-ARIA combobox pattern with a listbox that is always shown. The search box has role="combobox", aria-autocomplete="list", aria-expanded="true", aria-controls pointing to the list and the name "Search". The list is a role="listbox", named by label, of role="option" items; disabled ones carry aria-disabled. Focus stays in the search box and the highlighted item is exposed through aria-activedescendant. A search that finds nothing shows the no-records message in a live region. tk:command.modal is a native modal dialog named "Search".
| Key | Action |
|---|---|
| Arrow Down / Arrow Up | Highlights the next / previous item, wrapping around and skipping disabled ones. |
| Enter | Selects the highlighted item. |
| Tab | Selects the highlighted item and moves focus on. |
| Escape | Removes the highlight. In tk:command.modal, closes the modal. |
Without the search box the list itself is in the tab order, and Home / End highlight the first / last item and Space also selects.
Behavior notes
- The search ignores case and accents and matches anywhere in the label:
saofinds "São Paulo". After typing, the first match is highlighted; before that, nothing is until an arrow key is pressed. - Selecting an item fires a click on it, so its
wire:clickorx-on:clickruns, and thenselectedis dispatched. A disabled item cannot be selected and is not highlighted by the pointer. - With
clearOnSelectthe search box is emptied, but the list keeps the previous filter until the user types again or the box gets focus. - With the search box, the list has a maximum height that grows with
sizeand scrolls beyond it. Without it, the list shows every item at full height. - A Livewire update keeps the search text and re-applies it to the new items, and an open
tk:command.modalstays open. - Closing
tk:command.modalkeeps the search text: opened again, it shows the same filtered list.