Button
Trigger an action, submit a form, or navigate to a link. Buttons support theme colors, variants, icons, loading states, groups, and built-in popover hints.
Import
import { HuiButton } from '@nscode/handy-ui'
import type { ButtonProps, ButtonExpose } from '@nscode/handy-ui'
Examples
Colors and variants
type controls color. variant selects solid, outline, plain, text, or link styling. plain is a shorthand for variant="plain"; an explicitly different variant takes priority.
<script setup lang="ts">
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { ButtonType, ButtonVariant } from '@nscode/handy-ui'
const types: ButtonType[] = ['default', 'primary', 'success', 'warning', 'danger', 'info', 'help']
const variants: ButtonVariant[] = ['solid', 'outline', 'plain', 'text', 'link']
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace v-for="variant in variants" :key="variant" wrap
><span>{{ variant }}</span
><HuiButton v-for="type in types" :key="type" :type="type" :variant="variant">{{
type
}}</HuiButton></HuiSpace
>
<HuiSpace
><HuiButton plain type="primary">plain shorthand</HuiButton
><HuiButton plain variant="outline" type="primary"
>outline takes priority</HuiButton
></HuiSpace
>
</HuiSpace>
</template>
Pressed state
Explicit true or false enables toggle semantics and aria-pressed. Omitted or undefined keeps a regular button. A click requests update:pressed before click; rendering follows the parent value, with a stable button label.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
const pressed = ref(false)
const requested = ref<boolean>()
const updates = ref(0)
const clicks = ref(0)
const variants = ['solid', 'outline', 'plain', 'text', 'link'] as const
</script>
<template>
<HuiSpace class="button-pressed-demo" direction="vertical" fill>
<HuiSpace wrap>
<HuiButton
class="pressed-toggle"
v-model:pressed="pressed"
variant="outline"
@update:pressed="updates++"
@click="clicks++"
>Only mine</HuiButton
>
<HuiButton :pressed="false" @update:pressed="requested = $event">Parent rejects</HuiButton>
<HuiButton :pressed="true" disabled>Disabled</HuiButton>
<HuiButton :pressed="true" loading>Loading</HuiButton>
</HuiSpace>
<span class="pressed-status"
>Pressed: {{ pressed }}; updates: {{ updates }}; clicks: {{ clicks }}; rejected request:
{{ requested }}</span
>
<HuiSpace wrap>
<HuiButton
v-for="variant in variants"
:key="variant"
:variant="variant"
type="primary"
:pressed="true"
>{{ variant }}</HuiButton
>
</HuiSpace>
</HuiSpace>
</template>
Pressed solid buttons use the darker primary color; other variants use a soft primary background, primary text and border without changing spacing. Explicit custom colors keep their priority. Debounce and throttle apply to both events. A queued update uses the latest pressed value and is cancelled on disable, loading or unmount. href ignores pressed and warns in development. Use Button for action toggles, selectable Tag for filters, and Segmented or RadioGroup for mutually exclusive options.
Sizes and shapes
Large, default, and small use theme heights of 40, 32, and 24px. round creates pill corners. circle hides text and keeps a circular icon button; provide an accessible name.
<script setup lang="ts">
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { ButtonSize } from '@nscode/handy-ui'
const sizes: ButtonSize[] = ['large', 'default', 'small']
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace v-for="size in sizes" :key="size" wrap
><span>{{ size }}</span
><HuiButton :size="size">Default shape</HuiButton
><HuiButton :size="size" type="primary" round>Round</HuiButton
><HuiButton :size="size" type="primary" circle icon="search" :aria-label="`Search, ${size}`"
/></HuiSpace>
</HuiSpace>
</template>
Size and disabled inheritance inside forms
Size priority is button → ButtonGroup → InputGroup → ConfigProvider.button.size → ConfigProvider.size → default. Disabled state uses the first explicit value from button → ButtonGroup → InputGroup. An explicit false overrides an inherited disabled value; loading still blocks clicks.
Button does not directly inherit Form or FormItem size or disabled state. InputGroup merges its FormItem/Form size and Form disabled state into the group context, keeping grouped inputs and buttons aligned. A button outside InputGroup can remain clickable to enable a disabled form. An independent Form cuts off an outer input group.
<script setup lang="ts">
import { ref } from 'vue'
import {
HuiConfigProvider,
HuiForm,
HuiFormItem,
HuiInputGroup,
HuiInput,
HuiButton,
HuiSpace
} from '@nscode/handy-ui'
const disabled = ref(true)
</script>
<template>
<HuiConfigProvider size="large" :button="{ size: 'default' }">
<HuiForm size="large" :disabled="disabled">
<HuiFormItem label="Grouped small" size="small"
><HuiInputGroup
><HuiInput placeholder="Inherited FormItem small" /><HuiButton
>Grouped small</HuiButton
></HuiInputGroup
></HuiFormItem
>
<HuiSpace wrap
><HuiButton @click="disabled = !disabled"
>Outside group, default: {{ disabled ? 'Edit' : 'Disable form' }}</HuiButton
><HuiButton size="small">Own small</HuiButton
><span>Form disabled={{ disabled }}</span></HuiSpace
>
</HuiForm>
</HuiConfigProvider>
</template>
Icons in all positions
Icon-only buttons automatically use square proportions. icon-position accepts left, right, top, and bottom. Icons can also come from the default slot.
<script setup lang="ts">
import { HuiButton, HuiIcon, HuiSpace } from '@nscode/handy-ui'
import type { ButtonIconPosition } from '@nscode/handy-ui'
const positions: ButtonIconPosition[] = ['left', 'right', 'top', 'bottom']
</script>
<template>
<HuiSpace wrap align="start"
><HuiButton
v-for="position in positions"
:key="position"
type="primary"
icon="search"
:icon-position="position"
>{{ position }}</HuiButton
><HuiButton icon="edit" aria-label="Edit" /><HuiButton aria-label="Information"
><HuiIcon name="info" /></HuiButton
></HuiSpace>
</template>
Loading and disabled states
Loading replaces the icon and blocks clicks. Set loading-text to replace the label and loading-progress-bar for a bottom progress animation. Disabled controls emit no click event.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSwitch, HuiSpace } from '@nscode/handy-ui'
const loading = ref(false)
const disabled = ref(false)
const clicks = ref(0)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace
><span>loading</span><HuiSwitch v-model="loading" /><span>disabled</span
><HuiSwitch v-model="disabled"
/></HuiSpace>
<HuiSpace wrap
><HuiButton type="primary" :loading="loading" :disabled="disabled" @click="clicks++"
>Save</HuiButton
><HuiButton
type="primary"
:loading="loading"
:disabled="disabled"
loading-text="Saving…"
loading-progress-bar
@click="clicks++"
>With progress</HuiButton
><HuiButton icon="search" :loading="loading" :disabled="disabled" aria-label="Search"
/></HuiSpace>
<span>Accepted clicks: {{ clicks }}</span>
</HuiSpace>
</template>
Colors, borders, dimensions, and links
color sets a custom main color; text-color, bg-color, and border-color override individual parts. width and height accept pixels as numbers or CSS strings. Height cannot be smaller than the active size's minimum height. href renders an anchor; disabled or loading anchors have no href and expose aria-disabled.
<script setup lang="ts">
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace wrap
><HuiButton color="var(--hui-color-help)">Custom color</HuiButton
><HuiButton
text-color="var(--hui-color-primary)"
bg-color="var(--hui-color-primary-bg)"
border-color="var(--hui-color-primary)"
>Individual colors</HuiButton
><HuiButton type="primary" dashed>Dashed</HuiButton
><HuiButton type="primary" transparent>Transparent</HuiButton
><HuiButton type="primary" variant="outline" dashed>Dashed outline</HuiButton></HuiSpace
>
<HuiSpace wrap
><HuiButton :width="180" :height="48">180 × 48</HuiButton
><HuiButton width="50%">50% width</HuiButton></HuiSpace
>
<HuiSpace wrap
><HuiButton href="https://example.com" target="_blank" variant="link" underline
>Open link</HuiButton
><HuiButton href="https://example.com" disabled>Disabled link</HuiButton
><HuiButton href="https://example.com" loading>Loading link</HuiButton></HuiSpace
>
</HuiSpace>
</template>
Badges
<script setup lang="ts">
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { ButtonBadgePosition } from '@nscode/handy-ui'
const positions: ButtonBadgePosition[] = ['top-right', 'top-left', 'bottom-right', 'bottom-left']
</script>
<template>
<HuiSpace wrap
><HuiButton
v-for="position in positions"
:key="position"
badge="3"
:badge-position="position"
>{{ position }}</HuiButton
><HuiButton badge="New" badge-color="var(--hui-color-success)"
>Custom badge</HuiButton
></HuiSpace
>
</template>
Popover triggers and methods
The built-in hint defaults to hover, while standalone Popover defaults to click. Manual ignores mouse/focus and uses showPopover()/hidePopover(). popover-disabled closes an open hint. The button must also be enabled.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
import type { ButtonExpose } from '@nscode/handy-ui'
const manual = ref<ButtonExpose>()
const disabled = ref(false)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace><span>Disable hints</span><HuiSwitch v-model="disabled" /></HuiSpace>
<HuiSpace wrap
><HuiButton
popover
popover-title="Hover"
popover-content="Hover this button"
:popover-disabled="disabled"
>hover</HuiButton
><HuiButton
popover
popover-trigger="click"
popover-content="Click again to close"
:popover-disabled="disabled"
>click</HuiButton
><HuiButton
popover
popover-trigger="focus"
popover-content="Focus this button"
:popover-disabled="disabled"
>focus</HuiButton
><HuiButton
ref="manual"
popover
popover-trigger="manual"
popover-content="Controlled through methods"
:popover-disabled="disabled"
>manual</HuiButton
></HuiSpace
>
<HuiSpace wrap
><HuiButton @click="manual?.showPopover()">showPopover()</HuiButton
><HuiButton @click="manual?.hidePopover()">hidePopover()</HuiButton
><HuiButton @click="manual?.focus()">focus()</HuiButton
><HuiButton @mousedown.prevent @click="manual?.blur()">blur()</HuiButton></HuiSpace
>
</HuiSpace>
</template>
All popover placements
Placement flips automatically when the preferred side lacks space.
<script setup lang="ts">
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { ButtonProps } from '@nscode/handy-ui'
const placements: NonNullable<ButtonProps['popoverPlacement']>[] = [
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end',
'right',
'right-start',
'right-end'
]
</script>
<template>
<HuiSpace wrap
><HuiButton
v-for="placement in placements"
:key="placement"
popover
:popover-placement="placement"
:popover-content="placement"
>{{ placement }}</HuiButton
></HuiSpace
>
</template>
Debounce, throttle, and ripple
Debounce delays the click until activity stops. Throttle accepts the first click in its interval. If both are supplied, debounce takes priority. Ripple animates from the click position.
A queued click is cancelled if the button becomes disabled or loading, or its ButtonGroup becomes disabled. Restoring availability does not replay that click. Debounce controls the component click event; it does not delay native form submission with native-type="submit".
Click the delayed button, then toggle either state within one second to cancel its pending action:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
const disabled = ref(false)
const loading = ref(false)
const count = ref(0)
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiButton :debounce="1000" :disabled="disabled" :loading="loading" @click="count++">
Run after one second
</HuiButton>
<HuiButton @click="disabled = !disabled">{{ disabled ? 'Enable' : 'Disable' }}</HuiButton>
<HuiButton @click="loading = !loading">{{
loading ? 'Stop loading' : 'Start loading'
}}</HuiButton>
</HuiSpace>
<span>Completed actions: {{ count }}</span>
</HuiSpace>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
const searches = ref(0)
const submits = ref(0)
</script>
<template>
<HuiSpace direction="vertical" fill
><HuiSpace wrap
><HuiButton :debounce="500" @click="searches++">Debounce 500ms</HuiButton
><HuiButton :throttle="1000" @click="submits++">Throttle 1000ms</HuiButton
><HuiButton type="primary" ripple>Ripple</HuiButton></HuiSpace
><span>Searches {{ searches }}, submits {{ submits }}</span></HuiSpace
>
</template>
Native types and groups
native-type selects button, submit, or reset. Buttons default to button, so they do not submit a form accidentally. ButtonGroup supplies shared size, type, and disabled values; a button's own values take priority.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiButtonGroup, HuiSpace } from '@nscode/handy-ui'
const result = ref('No action yet')
</script>
<template>
<HuiSpace direction="vertical" fill>
<form @submit.prevent="result = 'Submitted'" @reset.prevent="result = 'Reset event received'">
<HuiSpace wrap
><HuiButton native-type="submit" type="primary">submit</HuiButton
><HuiButton native-type="reset">reset</HuiButton
><HuiButton native-type="button" @click="result = 'Button click'"
>button</HuiButton
></HuiSpace
>
</form>
<HuiButtonGroup type="primary" size="small"
><HuiButton icon="arrow-left">Previous</HuiButton
><HuiButton icon="arrow-right" icon-position="right">Next</HuiButton></HuiButtonGroup
>
<span>{{ result }}</span>
</HuiSpace>
</template>
Inherited Color Variable and Explicit Props
--hui-button-color colors the loading progress bar and participates in custom plain-button color mixing; it does not replace type or color. Set it on the button or any ancestor. The explicit color prop takes priority, followed by the public variable, then the theme primary color. Each button resets its private prop override so nested buttons do not inherit an outer button's explicit color.
The ordinary loading button inherits the success color for its progress bar. Another button has a local help-color variable and an explicit warning-color prop, so warning wins. Removing the prop restores the local help color; enabling it restores warning. Custom plain-button text, background tint, and border tint keep the same prop color. Existing priorities for textColor, bgColor, and borderColor remain unchanged.
Set the public variable on an ancestor class in a parent <style scoped>; :deep() is unnecessary.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace } from '@nscode/handy-ui'
const variableExplicit = ref(true)
const variableClicks = ref(0)
</script>
<template>
<div
class="button-variables-demo"
style="--hui-button-color:var(--hui-color-success);display:flex;flex-direction:column;gap:var(--hui-spacing-4)"
>
<HuiSpace wrap>
<HuiButton class="button-variable-toggle" @click="variableExplicit = !variableExplicit"
>Explicit color: {{ variableExplicit ? 'Enabled' : 'Unset' }}</HuiButton
>
<HuiButton class="button-variable-click" @click="variableClicks++">Normal button</HuiButton>
<span class="button-variable-result">Clicks: {{ variableClicks }}</span>
</HuiSpace>
<HuiSpace wrap>
<HuiButton class="button-variable-inherited" loading loading-progress-bar
>Inherited success progress</HuiButton
>
<HuiButton
class="button-variable-explicit"
:color="variableExplicit ? 'var(--hui-color-warning)' : undefined"
style="--hui-button-color:var(--hui-color-help)"
loading
loading-progress-bar
>Prop first, then local variable</HuiButton
>
<HuiButton
class="button-variable-plain"
color="var(--hui-color-warning)"
variant="plain"
style="--hui-button-color:var(--hui-color-help)"
>Plain custom color</HuiButton
>
</HuiSpace>
</div>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| type | 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'help' | Inherited / default | Own value, ButtonGroup type, then global button type |
| size | 'large' | 'default' | 'small' | Inherited | Own → ButtonGroup → InputGroup → ConfigProvider.button.size → ConfigProvider.size → default |
| variant | 'solid' | 'outline' | 'plain' | 'text' | 'link' | 'solid' | Visual variant |
| disabled | boolean | Inherited / false | First explicit own, ButtonGroup, or InputGroup value; Form does not directly disable buttons |
| loading | boolean | false | Show loading and block clicks |
| pressed | boolean | undefined | Explicit true/false enables toggle semantics; href ignores it; parent value controls rendering. |
| loadingText | string | — | Replacement loading label; omitted keeps the original label |
| loadingProgressBar | boolean | false | Animate a bottom progress bar while loading |
| icon | string | — | Icon name |
| iconPosition | 'left' | 'right' | 'top' | 'bottom' | 'left' | Icon position |
| plain | boolean | false | Shorthand for variant=plain |
| round | boolean | false | Pill corners |
| circle | boolean | false | Circular button without text |
| nativeType | 'button' | 'submit' | 'reset' | 'button' | Native button type |
| autofocus | boolean | false | Native autofocus, for button elements |
| color | string | — | Main color |
| textColor | string | — | Override text color |
| bgColor | string | — | Override background color |
| borderColor | string | — | Override border color |
| dashed | boolean | false | Dashed border |
| transparent | boolean | false | Transparent background |
| secondary | boolean | false | Deprecated; use variant, removed in 1.0 |
| tertiary | boolean | false | Deprecated; use variant, removed in 1.0 |
| quaternary | boolean | false | Deprecated; use variant, removed in 1.0 |
| width | string | number | — | CSS width; numeric values use px |
| height | string | number | — | CSS height; constrained by the active size's minimum |
| href | string | — | Render an anchor; removed while disabled or loading |
| target | '_blank' | '_self' | '_parent' | '_top' | — | Link target |
| underline | boolean | false | Underline for variant=link |
| badge | string | number | — | Badge content |
| badgeColor | string | Danger color | Badge background |
| badgePosition | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-right' | Badge position |
| popover | boolean | false | Enable a built-in hint |
| popoverContent | string | — | Hint body |
| popoverTitle | string | — | Hint title |
| popoverPlacement | PopperPlacement | 'top' | Twelve placements, with automatic flipping |
| popoverTrigger | 'hover' | 'click' | 'focus' | 'manual' | 'hover' | Hint trigger |
| popoverDisabled | boolean | false | Disable and close the hint |
| debounce | number | 0 | Debounce delay in milliseconds |
| throttle | number | 0 | Throttle interval in milliseconds |
| ripple | boolean | false | Animate a click ripple |
Events
| Event | Arguments | Description |
|---|---|---|
| click | (event: MouseEvent) | Accepted click; omitted while disabled/loading and filtered by debounce/throttle |
| update:pressed | (pressed: boolean) | Toggle request before click; debounce/throttle filter both events. |
Slots
| Slot | Description |
|---|---|
| default | Label or icon content; hidden for circle and when loadingText replaces it |
Methods
| Method | Type | Description |
|---|---|---|
| focus | () => void | Focus the button |
| blur | () => void | Blur the button |
| showPopover | () => void | Open an enabled hint on an enabled button; required for manual trigger |
| hidePopover | () => void | Close the hint |
Types
import type {
ButtonType,
ButtonSize,
ButtonVariant,
ButtonNativeType,
ButtonIconPosition,
ButtonBadgePosition,
ButtonProps,
ButtonExpose
} from '@nscode/handy-ui'