Button
v0.0.10
mix mishka.ui.gen.headless button
Link form
navigate renders a LiveView link that navigates, patch patches the current LiveView, and href renders a plain anchor. type, form, name and value belong to the button form and are ignored by links. An anchor has no native disabled, so a disabled or loading link gets aria-disabled="true" and data-disabled instead. The component does not cancel its click. Add aria-disabled:pointer-events-none to the classes to ignore pointer clicks, as the last example does.
Submitting forms
In the button form, type is button by default and accepts submit and reset. form names the id of the form to submit, and name and value are sent with it. While loading is set the button is natively disabled, so it cannot submit twice.
<.form for={@form} id="profile-form" phx-submit="save">
<.input field={@form[:name]} />
<.button type="submit" loading={@saving?} class="...">Save</.button>
<.button type="reset" class="...">Reset</.button>
</.form>Parts & data attributes
The root carries chelekom-button, data-disabled and data-loading. Each part has a data-part value and a chelekom-button__* class.
start-iconholds the:start_iconslot before the label. Class attribute:start_icon_class.loaderholds the:loaderslot and is rendered only whileloadingis set and the slot is given. Class attribute:loader_class.labelis always rendered. It holds thelabelattribute and the default slot. Class attribute:label_class.end-iconholds the:end_iconslot after the label. Class attribute:end_icon_class.
The icon and loader parts are marked aria-hidden, so the label is the button's accessible name.
Accessibility
Follows the WAI-ARIA Button pattern: Enter and Space activate the button. A busy button exposes aria-busy. A button with only an icon needs an accessible name, which the headless Action Icon requires for you.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
string
| — | — | No | Optional unique id |
type
|
string
|
button
|
buttonsubmitreset
| No | Native button type (ignored by the link form) |
disabled
|
boolean
|
false
| — | No | Disable the button (also sets data-disabled) |
loading
|
boolean
|
false
| — | No | Mark the button busy: aria-busy, data-loading, non-interactive, loader shown |
label
|
string
| — | — | No | Label text (or use the default slot) |
navigate
|
string
| — | — | No | Navigates to another LiveView |
patch
|
string
| — | — | No | Patches the current LiveView |
href
|
string
| — | — | No | Link target — renders a link instead of a button |
form
|
string
| — | — | No | Id of the form this button submits |
name
|
string
| — | — | No | Name submitted with the form |
value
|
string
| — | — | No | Value submitted with the form |
class
|
any
| — | — | No | Extra classes for the root |
label_class
|
any
| — | — | No | — |
loader_class
|
any
| — | — | No | — |
start_icon_class
|
any
| — | — | No | — |
end_icon_class
|
any
| — | — | No | — |
rest
|
global
| — | — | No | Any button/anchor/global attrs, e.g. phx-click |
Slots
| Name | Required | Description |
|---|---|---|
start_icon
| No | Icon before the label |
end_icon
| No | Icon after the label |
loader
| No | Shown while loading — bring your own spinner |
inner_block
| No | Label content, used when the label attr is not set |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
button
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.headless button