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.

Blade

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.

Search: "laravel"
Blade

With a text label #

A string in clearable becomes the button text, shown next to the icon, in place of the "Clear input" tooltip.

Blade

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.

Blade

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.

Blade

Cleared event #

cleared is dispatched on the input and bubbles: listen on the tk:input tag, here to call a Livewire action.

Cleared 0 times
Blade

Customization #

From tk:input, the clearable: prefix reaches the button: classes, icon and tooltip pass through to its tk:button.

Blade

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:

blade

Calling a Livewire action:

blade

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).

blade

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:input element inside the same field control ([data-tallkit-field-control]), so the button must sit inside it, as in the append slot.
  • 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, through x-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 readonly does nothing, and action does not run.
  • It keeps its visibility across Livewire updates of the page (wire:ignore.self).