WlButton
On this page
Variant and tone
Variant sets the button’s appearance. Tone sets its color. Choose Auto to use the color associated with the variant.
Clicks: 0
Full example
<WlButton variant="primary" @click="count++">
Add
</WlButton>Compare variants and tones
Size and density
Compare the four sizes from xs to lg. Compact density reduces the height within each size.
Clicks: 0
Full example
<WlButton size="md" density="default" @click="count++">
Add
</WlButton>Compare all four sizes
Loading and disabled
Turn on loading to see the spinner. Both loading and disabled prevent another click.
Clicks: 0
Full example
<WlButton @click="count++">
Add
</WlButton>Try saving, cancelling and retrying
Icon position
Pass an icon into the icon slot. Use start to place it before the label or end to place it after.
Clicks: 0
Full example
<WlButton icon-position="start" @click="count++">
<template #icon>
<WlIcon name="arrow-right" :size="16" />
</template>
Continue
</WlButton>Explore other slot examples
Buttons in forms
A submit button submits the form. A reset button resets it. Try both and watch the submission count. Turn on block to fill the available width.
Full example
<WlButton as="button" type="submit">
Apply
</WlButton>Open the form with field validation
When to use
- primary is the group's primary action; secondary is secondary.
- ghost and link are less prominent actions; tone="danger" marks actions that may delete data.
- block fills the available width; size and density change dimensions and spacing while preserving the DOM contract.
To use the button as a link, pass a URL with href.
Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
variant | WlButtonVariant | "secondary" | Visual button variant. |
tone | WlTone | Not set | Semantic color, independent of the visual treatment. |
size | WlSize | "md" | Button size. |
density | WlDensity | "default" | Compact mode reduces button height. |
loading | boolean | false | Shows loading instead of the icon and blocks clicks. |
disabled | boolean | false | Disables the button. |
block | boolean | false | Fill the container width. |
type | "button" | | "button" | Native button type. |
pt | WlPt< | Not set | Attributes of internal Legato UI elements. |
as | "button" | | Not set | Render a link explicitly; href or to also selects link rendering. |
href | string | Not set | Link destination, forwarded to WlLink. |
to | unknown | Not set | Application router destination handled by the configured link adapter. |
iconPosition | "start" | | Not set | Place the icon before or after the default slot. |
Events
| Event | Payload | When emitted |
|---|---|---|
click | [event: MouseEvent] | Click (not emitted when disabled/loading). |
Slots
| Slot | Type / values | Content |
|---|---|---|
default | — | Text or other button content. |
icon | — | Leading icon (hidden while loading). |
Pass-through: pt
Sections WlButton are listed below. Attributes merge in this order: createWlPt() WlConfig.pt.buttonpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | button | Root button attributes, additional class and style. |
label | span.wl-btn__label | Default slot wrapper. Appears when content is passed to the slot. |
loadingIcon | span.wl-btn__spinner | Loading spinner; hidden from assistive technology. |
The icon is passed through the iconslot; it has no separate pt section. Class, style, aria-* and data-* can be passed to the button itself. The root preserves data-wl="button", data-variant, data-size and data-density.
Keyboard and states
Keyboard and application responsibilities
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move between enabled links, actions and form controls. |
| Enter / Space | Activate native actions; links follow with Enter. |
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring Practices- Tab focuses an available button; Enter or Space runs its action. Focus is visible in every theme.
- When
disabledorloadingthe nativedisabledblocks clicks and removes the button from the Tab order. loadingsetsaria-busy="true". The spinner hasaria-hidden="true"; the button text remains its accessible name.- Explain why an action is unavailable next to it. Do not convey meaning through colour or an icon alone.
- An icon-only button needs an accessible name, such as
aria-label. WlIconButton also supports this case. - Inside a form, set
type="submit"ortype="reset"deliberately; the default istype="button", which does not submit the form.
Check this page: return to the examples, select “Focus the example”, press Enter/Space and check the counter. Then enable disabled or loading: the action should stop running.