Forms
Clearable
A small button that empties the input it sits next to and puts the focus back in it. It is usually added through the clearable prop of tk:input; use the tag directly to place it yourself or to run an action of your own when it is clicked.
Nothing to show
An input with an "×" button at its end. The button shows only while the input has a value; clicking it empties the input, keeps the focus there and hides itself until something is typed again.
Bound to Livewire #
Clicking the button sets $search to ''. Clearing fires the input's input and change events, so wire:model and x-model pick up the empty value like any typing; with .live the request goes out at once.
Nothing to show
With a text label #
A string in clearable becomes the button text, shown next to the icon, in place of the "Clear input" tooltip.
Nothing to show
Placed by hand, with an action #
tk:clearable works anywhere inside the control of a field. On click, action runs instead of emptying the input, so it clears the value itself (here query, and page goes back to 1); without action, the input is emptied.
Nothing to show
Outside a field #
With no field around it there is no input to empty: the button is always visible, and clicking it only runs action and fires cleared.
Nothing to show
Cleared event #
cleared is dispatched on the input and bubbles: listen on the tk:input tag, here to call a Livewire action.
Nothing to show
Customization #
From tk:input, the clearable: prefix reaches the button: classes, icon and tooltip pass through to its tk:button.
Nothing to show
Reference
tk:clearable
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
Visible text next to the icon, translated. Without a label or slot content the button shows only the icon, with the tooltip "Clear input". |
action |
string | null |
An Alpine expression evaluated on click, in the scope of the button, instead of emptying the input: it owns the value. |
Also accepts the element props (icon, badge, ariaLabel...). icon defaults to mdi:close; :icon="false" removes it.
Slots
| Slot | Description |
|---|---|
| default | The button text, in place of the label prop. |
Events
| Event | Detail | When |
|---|---|---|
cleared |
The button was clicked: the input was emptied or, with action, the action ran (the action owns the value and the input is not emptied). |
Through tk:input
| Prop | Type | Default | Description |
|---|---|---|---|
clearable |
bool | string | false |
Adds the button at the end of the control. A string is its label. |
Prefixes
| Prefix | Goes to |
|---|---|
clearable: |
The clear button. |
Events
The event is dispatched on the input the button cleared and bubbles, so listen on the tk:input tag or on any element around it, not on tk:clearable (nor with clearable:@cleared). A tk:clearable with no input around it dispatches the event on itself.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes and attributes on tk:clearable go to its <button>, which is a tk:button with variant="none": other tk:button props such as variant, size and tooltip pass through. From tk:input, prefix them (listed in the Reference above).
Nothing to show
Accessibility
A native <button type="button">. Its accessible name is the label, or the tooltip text ("Clear input", translated) when there is no label and no slot content. The button does not take the focus on mouse down, and after clearing the focus goes back to the input.
| Key | Action |
|---|---|
| Tab | From the input, moves to the button while it is visible. |
| Enter, Space | Clears the input and moves the focus back to it. |
Behavior notes
- The input is the first
tk:inputelement inside the same field control ([data-tallkit-field-control]), so the button must sit inside it, as in theappendslot. - The button is hidden while the input is empty, disabled or
readonly, and before Alpine starts (x-cloak). It shows again when the input gets a value by typing, throughx-model, from a Livewire update or after a form reset. A number input holding text the browser cannot parse counts as not empty. - Clicking it while the input is disabled or
readonlydoes nothing, andactiondoes not run. - It keeps its visibility across Livewire updates of the page (
wire:ignore.self).