Chip
A compact label with optional icons, avatars, and a remove button. Inside HuiChipGroup, chips can be selected for filters or selected-item lists. Use Tag when only displaying status or categories.
Import
import { HuiChip, HuiChipGroup } from '@nscode/handy-ui'
Internal state and controlled updates
With modelValue omitted or only an update listener, selection is stored internally: multiple mode starts from an empty array, and single mode starts from null. Supplying the prop, including undefined, makes it controlled; undefined displays the current mode's empty state. Parent rejection keeps the actual parent value. Requests preserve update → change ordering.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup, HuiButton, HuiSpace } from '@nscode/handy-ui'
const q1Redraw = ref(0)
const q1Last = ref('No request yet')
const q1Model = ref([] as (string | number)[])
</script>
<template>
<div class="chip-q1-demo">
<HuiButton class="q1-redraw" @click="q1Redraw++">Parent redraw {{ q1Redraw }}</HuiButton>
<HuiSpace direction="vertical" fill>
<div>
<p>Prop omitted: internal state</p>
<div class="q1-local">
<HuiChipGroup
><HuiChip value="a" label="A" /><HuiChip value="b" label="B" /><HuiChip
value="c"
label="Disabled"
disabled
/></HuiChipGroup>
</div>
</div>
<div>
<p>Listener only: internal state</p>
<div class="q1-listener">
<HuiChipGroup @update:model-value="q1Last = JSON.stringify($event)"
><HuiChip value="a" label="A" /><HuiChip value="b" label="B" /><HuiChip
value="c"
label="Disabled"
disabled
/></HuiChipGroup>
</div>
</div>
<div>
<p>Explicit undefined: parent value</p>
<div class="q1-empty">
<HuiChipGroup :model-value="undefined"
><HuiChip value="a" label="A" /><HuiChip value="b" label="B" /><HuiChip
value="c"
label="Disabled"
disabled
/></HuiChipGroup>
</div>
</div>
<div>
<p>Fixed controlled value: parent rejects updates</p>
<div class="q1-fixed">
<HuiChipGroup :model-value="['a']" @update:model-value="q1Last = JSON.stringify($event)"
><HuiChip value="a" label="A" /><HuiChip value="b" label="B" /><HuiChip
value="c"
label="Disabled"
disabled
/></HuiChipGroup>
</div>
</div>
<div>
<p>Two-way binding</p>
<div class="q1-bound">
<HuiChipGroup v-model="q1Model"
><HuiChip value="a" label="A" /><HuiChip value="b" label="B" /><HuiChip
value="c"
label="Disabled"
disabled
/></HuiChipGroup>
</div>
</div>
<p class="q1-notification">Bound value: {{ q1Model }}; latest request: {{ q1Last }}</p>
</HuiSpace>
</div>
</template>
Basic usage
Pass text through label or use the default slot.
<script setup lang="ts">
import { HuiChip, HuiSpace } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace wrap>
<HuiChip label="Text from label" />
<HuiChip>Text from the slot</HuiChip>
</HuiSpace>
</template>
Types
type controls color and accepts primary, success, warning, danger, and info, defaulting to primary.
<script setup lang="ts">
import { HuiChip, HuiSpace } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace wrap>
<HuiChip label="primary" type="primary" />
<HuiChip label="success" type="success" />
<HuiChip label="warning" type="warning" />
<HuiChip label="danger" type="danger" />
<HuiChip label="info" type="info" />
</HuiSpace>
</template>
Outlined chips
outline makes the background transparent and uses the type color for the border. Selection inside HuiChipGroup produces a solid type-colored background with white text, including for outlined chips.
Each row compares all five types. The third row is a group with all chips selected; click to deselect:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup, HuiSpace } from '@nscode/handy-ui'
const selected = ref<(string | number)[]>(['primary', 'success', 'warning', 'danger', 'info'])
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">Default</span>
<HuiChip label="Primary" type="primary" />
<HuiChip label="Success" type="success" />
<HuiChip label="Warning" type="warning" />
<HuiChip label="Danger" type="danger" />
<HuiChip label="Info" type="info" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">outline</span>
<HuiChip label="Primary" type="primary" outline />
<HuiChip label="Success" type="success" outline />
<HuiChip label="Warning" type="warning" outline />
<HuiChip label="Danger" type="danger" outline />
<HuiChip label="Info" type="info" outline />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">Selected</span>
<HuiChipGroup v-model="selected">
<HuiChip value="primary" label="Primary" type="primary" />
<HuiChip value="success" label="Success" type="success" />
<HuiChip value="warning" label="Warning" type="warning" />
<HuiChip value="danger" label="Danger" type="danger" />
<HuiChip value="info" label="Info" type="info" />
</HuiChipGroup>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Sizes
size accepts large, default, and small. Respective dimensions are: height 32/24/18px, text 16/14/12px, leading icon 18/16/14px, avatar 24/20/16px, and remove button 16/14/12px. Icons, avatars, and removal do not change overall height. When omitted, size follows the group, then HuiConfigProvider, and finally default.
<script setup lang="ts">
import { HuiChip, HuiSpace } from '@nscode/handy-ui'
// Replace with your image URL
const avatar = '/images/user.png'
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap align="center">
<span class="row-label">large</span>
<HuiChip label="Text" size="large" />
<HuiChip label="Icon" size="large" icon="user" />
<HuiChip label="Avatar" size="large" :image="avatar" />
<HuiChip label="Removable" size="large" removable />
<HuiChip label="Outline" size="large" outline />
</HuiSpace>
<HuiSpace wrap align="center">
<span class="row-label">default</span>
<HuiChip label="Text" />
<HuiChip label="Icon" icon="user" />
<HuiChip label="Avatar" :image="avatar" />
<HuiChip label="Removable" removable />
<HuiChip label="Outline" outline />
</HuiSpace>
<HuiSpace wrap align="center">
<span class="row-label">small</span>
<HuiChip label="Text" size="small" />
<HuiChip label="Icon" size="small" icon="user" />
<HuiChip label="Avatar" size="small" :image="avatar" />
<HuiChip label="Removable" size="small" removable />
<HuiChip label="Outline" size="small" outline />
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Icons and images
icon accepts an HuiIcon name and displays it before the text in the text color. Use the icon slot for custom content. image displays a circular avatar before the text and also rounds both chip ends.
<script setup lang="ts">
import { HuiChip, HuiSpace } from '@nscode/handy-ui'
// Replace with your image URL
const avatar = '/images/user.png'
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiChip label="icon prop" icon="user" />
<HuiChip label="icon slot">
<template #icon><span>★</span></template>
</HuiChip>
<HuiChip label="image prop" :image="avatar" />
<HuiChip label="Avatar with removal" :image="avatar" removable />
</HuiSpace>
<HuiSpace wrap>
<HuiChip label="Completed" type="success" icon="success" />
<HuiChip label="Pending" type="warning" icon="clock" />
<HuiChip label="Rejected" type="danger" icon="error" />
<HuiChip label="Draft" type="info" icon="file" />
<HuiChip label="Favorite" type="warning" icon="star" outline />
<HuiChip label="Location" type="info" icon="location" outline />
</HuiSpace>
</HuiSpace>
</template>
Removable chips
removable adds a remove button on the right, supporting every type and outline style. Replace its icon with the remove slot.
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiChip label="Primary" type="primary" removable />
<HuiChip label="Success" type="success" removable />
<HuiChip label="Warning" type="warning" removable />
<HuiChip label="Danger" type="danger" removable />
<HuiChip label="Info" type="info" removable />
</HuiSpace>
<HuiSpace wrap>
<HuiChip label="Primary" type="primary" outline removable />
<HuiChip label="Success" type="success" outline removable />
<HuiChip label="Warning" type="warning" outline removable />
<HuiChip label="Danger" type="danger" outline removable />
<HuiChip label="Info" type="info" outline removable />
</HuiSpace>
</HuiSpace>
</template>
The remove button emits only remove: it does not hide the chip, emit click, or change selection. Confirm the chip name and single-item scope with HuiMessageBox.confirm before updating the collection. Canceling, closing, or pressing Esc preserves the data.
ChipGroup moves focus to a neighboring enabled chip after the focused item is actually removed. For standalone Chip instances, the application handles focus return; the confirmation example below focuses the neighboring remove button.
While confirmation is pending, the pending guard blocks duplicate requests and remove buttons remain focusable. Canceling, closing, or pressing Esc returns focus to the original button. Successful removal focuses the next button, or the previous one when removing the last chip. Refreshing, restoring, changing read-only state, changing the collection, or unmounting invalidates a late confirmation. Restore all chips resets this example's data. Read-only mode prevents removal requests.
<script setup lang="ts">
import { nextTick, onBeforeUnmount, ref, watch } from 'vue'
import { HuiButton, HuiChip, HuiMessageBox, HuiSpace } from '@nscode/handy-ui'
const initial = ['Vue', 'React', 'Angular', 'Svelte', '自定义移除图标']
const chips = ref(initial.slice())
const pending = ref(false)
const readonly = ref(false)
const status = ref('Click a remove button; the chip is removed only after confirmation')
let alive = true
let revision = 0
watch([chips, readonly], () => revision++, { deep: true, flush: 'sync' })
const remove = async (name: string, event: MouseEvent) => {
if (!alive || pending.value || readonly.value || !chips.value.includes(name)) return
const collection = chips.value
const removedIndex = collection.indexOf(name)
const root = (event.currentTarget as HTMLElement | null)?.closest('.chip-remove-demo')
const snapshot = collection.slice()
const request = ++revision
pending.value = true
status.value = `Waiting to remove ${name}; the chip is preserved for now`
try {
const result = await HuiMessageBox.confirm(
`Remove chip “${name}”? Only this chip is removed; other chips remain unchanged.`,
'Remove chip',
{ confirmButtonText: 'Remove', confirmButtonType: 'danger' }
)
if (!alive) return
if (
readonly.value ||
request !== revision ||
chips.value !== collection ||
collection.length !== snapshot.length ||
snapshot.some((item, index) => item !== collection[index])
) {
status.value =
'Chips changed or read-only mode was entered. Removal canceled; confirm again.'
return
}
if (result.action !== 'confirm') {
status.value = 'Removal canceled; all chips are preserved'
return
}
chips.value = collection.filter((item) => item !== name)
await nextTick()
if (root?.isConnected) {
const buttons = root.querySelectorAll<HTMLButtonElement>('.hui-chip__remove')
buttons[Math.min(removedIndex, buttons.length - 1)]?.focus()
}
status.value = `Removed ${name}; other chips remain unchanged`
} catch {
if (alive && request === revision)
status.value = 'Confirmation canceled or closed; all chips are preserved'
} finally {
if (alive) pending.value = false
}
}
const restore = () => {
revision += 1
chips.value = initial.slice()
status.value = 'All chips restored; previous confirmation invalidated'
}
const refreshOrder = () => {
revision += 1
chips.value = chips.value.slice().reverse()
status.value = 'Chip order refreshed; previous confirmation invalidated'
}
const toggleReadonly = () => {
revision += 1
readonly.value = !readonly.value
status.value = readonly.value
? 'Read-only mode prevents removal; previous confirmation invalidated'
: 'Editing enabled'
}
onBeforeUnmount(() => {
alive = false
revision += 1
})
</script>
<template>
<HuiSpace class="chip-remove-demo" direction="vertical" fill>
<HuiSpace wrap>
<HuiChip
v-for="chip in chips"
:key="chip"
:label="chip === '自定义移除图标' ? 'Custom remove icon' : chip"
:type="chip === '自定义移除图标' ? 'warning' : 'primary'"
:disabled="readonly"
removable
@remove="remove(chip, $event)"
>
<template v-if="chip === '自定义移除图标'" #remove><span>✕</span></template>
</HuiChip>
</HuiSpace>
<HuiSpace wrap>
<HuiButton class="chip-remove-restore" size="small" icon="refresh" @click="restore"
>Restore all chips</HuiButton
>
<HuiButton class="chip-remove-refresh" size="small" @click="refreshOrder"
>Refresh chip order</HuiButton
>
<HuiButton class="chip-remove-readonly" size="small" @click="toggleReadonly">{{
readonly ? 'Enable editing' : 'Make read-only'
}}</HuiButton>
</HuiSpace>
<span class="chip-remove-status" role="status">{{ status }}</span>
<span class="chip-remove-remaining"
>Remaining: {{ chips.join('、') || '(empty)' }}; confirmation pending: {{ pending }}</span
>
<span
>Repeated removal is blocked while pending. Canceling or closing preserves data; refreshing,
restoring, read-only changes, or unmounting invalidate confirmation.</span
>
</HuiSpace>
</template>
Disabled
Disabled chips are dimmed with an unavailable cursor. They emit neither click nor removal events, and their remove buttons cannot receive focus. All types, outlined styles, and selected chips can be disabled.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup, HuiSpace } from '@nscode/handy-ui'
const selected = ref<(string | number)[]>(['a', 'b'])
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiChip label="Primary" type="primary" disabled />
<HuiChip label="Success" type="success" disabled />
<HuiChip label="Warning" type="warning" disabled />
<HuiChip label="Danger" type="danger" disabled />
<HuiChip label="Info" type="info" disabled />
</HuiSpace>
<HuiSpace wrap>
<HuiChip label="Disabled and removable" disabled removable />
<HuiChip label="Outlined and disabled" outline disabled />
<HuiChip label="Icon and disabled" icon="lock" disabled />
<HuiChipGroup v-model="selected">
<HuiChip value="a" label="Selected and disabled" disabled />
<HuiChip value="b" label="Selected and clickable" />
</HuiChipGroup>
</HuiSpace>
</HuiSpace>
</template>
Multiple selection
Place HuiChip components in HuiChipGroup and bind an array with v-model. Each chip supplies its value. Clicking toggles selection; selected chips become solid. A selection change emits change.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup } from '@nscode/handy-ui'
const selected = ref<(string | number)[]>(['vue', 'react'])
const changeCount = ref(0)
const handleChange = () => {
changeCount.value += 1
}
</script>
<template>
<HuiChipGroup v-model="selected" @change="handleChange">
<HuiChip value="vue" label="Vue" />
<HuiChip value="react" label="React" />
<HuiChip value="angular" label="Angular" />
<HuiChip value="svelte" label="Svelte" />
</HuiChipGroup>
<p style="margin-top: 12px">
Selected: {{ selected.length ? selected.join('、') : 'None' }}(change emitted
{{ changeCount }} times)
</p>
</template>
Group type, size, and outline
Set type, size, and outline on the group to share them. Explicit chip props take precedence. Selected outlined chips still become solid.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup, HuiSpace } from '@nscode/handy-ui'
const outlined = ref<(string | number)[]>(['b'])
const mixed = ref<(string | number)[]>(['a'])
const large = ref<(string | number)[]>(['a'])
const small = ref<(string | number)[]>(['a'])
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiChipGroup v-model="outlined" type="danger" outline>
<HuiChip value="a" label="Outlined when unselected" />
<HuiChip value="b" label="Solid when selected" />
</HuiChipGroup>
<HuiChipGroup v-model="mixed" type="primary">
<HuiChip value="a" label="Follow group (primary)" />
<HuiChip value="b" label="Own type=warning" type="warning" />
<HuiChip value="c" label="Own size=small" size="small" />
</HuiChipGroup>
<HuiChipGroup v-model="large" type="success" size="large">
<HuiChip value="a" label="Group size=large" />
<HuiChip value="b" label="Group type=success" />
</HuiChipGroup>
<HuiChipGroup v-model="small" type="info" size="small">
<HuiChip value="a" label="Group size=small" />
<HuiChip value="b" label="Group type=info" />
<HuiChip value="c" label="Own outline=false" :outline="false" />
</HuiChipGroup>
</HuiSpace>
</template>
Disabled groups
A group's disabled applies to chips that omit their own disabled prop. A chip with explicit :disabled="false" takes precedence and can remain enabled inside a disabled group.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup } from '@nscode/handy-ui'
const selected = ref<(string | number)[]>(['a'])
</script>
<template>
<HuiChipGroup v-model="selected" disabled>
<HuiChip value="a" label="Option A" />
<HuiChip value="b" label="Option B" />
<HuiChip value="c" label="Option C (independently enabled)" :disabled="false" />
</HuiChipGroup>
<p style="margin-top: 12px">Selected: {{ selected.join('、') || 'None' }}</p>
</template>
Use the checkbox to toggle the group's disabled state:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCheckbox, HuiChip, HuiChipGroup, HuiSpace } from '@nscode/handy-ui'
const disabled = ref(true)
const selected = ref<(string | number)[]>(['day'])
</script>
<template>
<HuiSpace wrap align="center">
<HuiCheckbox v-model="disabled">Disabled</HuiCheckbox>
<HuiChipGroup v-model="selected" :disabled="disabled" outline>
<HuiChip value="day" label="Today" />
<HuiChip value="week" label="This week" />
<HuiChip value="month" label="This month" />
</HuiChipGroup>
</HuiSpace>
</template>
Keyboard interaction
In the default multiple mode, each available chip with a value is a Tab stop and Enter/Space toggles it. Single mode uses one group stop and the radio navigation described below. Standalone or disabled chips are not focusable.
For standalone chips, the native remove button keeps its Tab stop and Enter/Space emits remove. Inside selectable groups, remove buttons do not add Tab stops: focus the chip and press Delete or Backspace to request removal. Disabled chips do not emit removal requests.
Ancestor appearance overrides
The component reads public variables and uses default colors/sizes when unset. Configure variables on a chip or any ancestor to share them with descendants. Selection and outline styles do not redefine public values. Nested chips inherit the outer public configuration while independently calculating their private type/size defaults.
Configure normal and selected states separately. --hui-chip-color, --hui-chip-bg, and --hui-chip-border-color affect unselected chips. Selected chips read their corresponding -selected variables, falling back to the type color and white text independently of normal-state overrides.
| Variable | Default | Description |
|---|---|---|
--hui-chip-color | Type color | Normal text and icon color |
--hui-chip-bg | Tinted type color; transparent for outline | Normal background color |
--hui-chip-border-color | Light type border; type color for outline | Normal border color |
--hui-chip-color-selected | White | Selected text and icon color |
--hui-chip-bg-selected | Type color | Selected background color |
--hui-chip-border-color-selected | Type color | Selected border color |
--hui-chip-icon-size | large/default/small: 18/16/14px | Leading icon size |
--hui-chip-remove-size | large/default/small: 16/14/12px | Remove button and icon size |
--hui-chip-border was renamed to --hui-chip-border-color without an old-name fallback. Intermediate color variables are internal implementation details, not public override APIs.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiChip, HuiChipGroup, HuiSpace } from '@nscode/handy-ui'
const variableSelection = ref<(string | number)[]>(['selected'])
</script>
<template>
<HuiSpace
class="chip-variables-demo"
direction="vertical"
fill
style="--hui-chip-color: var(--hui-color-danger); --hui-chip-bg: var(--hui-color-danger-light-9); --hui-chip-border-color: var(--hui-color-danger); --hui-chip-color-selected: var(--hui-color-white); --hui-chip-bg-selected: var(--hui-color-success); --hui-chip-border-color-selected: var(--hui-color-success); --hui-chip-icon-size: 20px; --hui-chip-remove-size: 18px"
>
<span
>Normal and outlined chips use red; selected chips use green. Both sets of public variables
and icon sizes are configured only on the ancestor.</span
>
<HuiChipGroup v-model="variableSelection">
<HuiChip value="base" label="Default" icon="user" removable />
<HuiChip value="outline" label="Outline" outline icon="user" />
<HuiChip value="selected" label="Selected" icon="user" removable />
</HuiChipGroup>
<span class="chip-variables-value">Selected: {{ variableSelection }}</span>
</HuiSpace>
</template>
Single Selection and Data Options
HuiChipGroup uses multiple selection by default. With multiple=false, its value is a string, number, or null. Clicking the selected item again, or pressing Enter or Space on it, clears to null. Numeric and string values match strictly.
options accepts object, string, or numeric arrays. An explicitly supplied options prop, including undefined or an empty array, takes precedence over the default slot. Supplying both produces a development warning.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import {
HuiButton,
HuiChip,
HuiChipGroup,
HuiForm,
HuiFormItem,
HuiSpace
} from '@nscode/handy-ui'
import type { ChipGroupOption, ChipGroupValue } from '@nscode/handy-ui'
const multiple = ref(false)
const value = ref<ChipGroupValue>(null)
const request = ref('No request')
const readonly = ref(false)
const model = reactive<{ category: ChipGroupValue }>({ category: null })
const options: ChipGroupOption[] = [
{ value: 1, label: 'Number 1', icon: 'home' },
{ value: '1', label: 'String 1', type: 'success' },
{ value: 'disabled', label: 'Unavailable', disabled: true }
]
const rules = {
category: [{ required: true, message: 'Choose a category', trigger: 'change' as const }]
}
const toggleMode = () => {
multiple.value = !multiple.value
value.value = multiple.value ? [] : null
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="toggleMode">Mode: {{ multiple ? 'Multiple' : 'Single' }}</HuiButton>
<HuiChipGroup
v-model="value"
:multiple="multiple"
:options="options"
aria-label="Category selection"
/>
<span>Selected: {{ JSON.stringify(value) }}</span>
<HuiChipGroup
:multiple="false"
:model-value="'a'"
aria-label="Fixed parent selection"
@change="request = JSON.stringify($event)"
>
<HuiChip value="a" label="A" />
<HuiChip value="b" label="B" />
</HuiChipGroup>
<span>Requested: {{ request }}</span>
<HuiChipGroup :options="['Documents', 'Images', 'Audio']" aria-label="Multiple categories" />
<HuiButton @click="readonly = !readonly">Form readonly: {{ readonly }}</HuiButton>
<HuiForm :model="model" :rules="rules" :readonly="readonly" size="small">
<HuiFormItem label="Category" prop="category">
<HuiChipGroup
v-model="model.category"
:multiple="false"
:options="['Documents', 'Images']"
/>
</HuiFormItem>
</HuiForm>
</HuiSpace>
</template>
Single selection uses radiogroup / radio with one Tab stop. All four arrow keys wrap, skip disabled items, and select; Home/End select the first/last available item. Enter or Space on the selected item clears it. Multiple selection keeps group / checkbox, with each available chip independently tabbable.
Remove buttons inside selectable groups do not add Tab stops. Focus a removable chip and press Delete or Backspace to request removal; aria-keyshortcuts="Delete" advertises the shortcut. Removal only emits remove, and the application confirms before changing the collection. Keys from editable slot content, composition, modifiers, or auto-repeat do not remove chips. Standalone Chip instances retain the remove button's native Tab stop.
During SSR and initial hydration, the group provides a temporary Tab stop while chip items have tabindex=-1. After mounting, actual DOM order transfers that stop to the selected or first available item, including chips inside wrapper components. Focus already on the group moves into the appropriate item; external focus stays put.
A controlled group displays and validates the actual parent value. Rejected requests do not change selection. Changing modes does not rewrite the parent value: arrays in single mode and scalars in multiple mode display that mode's empty state without corrective events.
Form disabled, readonly, and size settings are inherited; readonly falls back to disabled and individual disabled=false cannot override that limit. Only actual selection changes trigger FormItem change validation. Set validateEvent=false to disable it; focus changes and rejected requests do not validate.
HuiChip Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | number | - | Value used for selection in HuiChipGroup; chips without a value cannot be selected |
| label | string | - | Displayed text, replaced by the default slot; also used as the image alt |
| disabled | boolean | - | Disabled state; follows the group when omitted, otherwise defaults to false |
| removable | boolean | false | Whether to show the remove button |
| icon | string | - | Leading icon name |
| image | string | - | Image URL for a circular leading avatar |
| type | 'primary' | 'success' | 'warning' | 'danger' | 'info' | - | Type; follows the group when omitted, defaulting to 'primary' outside a group |
| size | 'large' | 'default' | 'small' | - | Size; follows the group, then HuiConfigProvider, then 'default' |
| outline | boolean | - | Outlined style; follows the group when omitted, otherwise defaults to false |
HuiChipGroup Props
| Prop | Type | Default | Description |
|---|---|---|---|
| modelValue | ChipGroupValue | undefined | Array in multiple mode; string, number, or null in single mode. Supplying the prop, including undefined, makes it controlled. |
| disabled | boolean | false | Disable chips in the group |
| size | 'large' | 'default' | 'small' | - | Follows FormItem, Form, then ConfigProvider, with default as the final fallback. |
| type | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'primary' | Group chip type |
| outline | boolean | false | Whether group chips are outlined |
| multiple | boolean | true | Multiple array selection, or scalar/null single selection; selecting the current single item again clears it. |
| options | ChipGroupOption[] | string[] | number[] | - | Explicit data, including undefined or an empty array, takes precedence over the default slot. |
| validateEvent | boolean | true | Validate actual selection changes through the containing FormItem. |
HuiChip Events
| Event | Parameters | Description |
|---|---|---|
| click | (event: MouseEvent) | Emitted on chip clicks, excluding remove-button clicks and disabled chips |
| remove | (event: MouseEvent) | Emitted on remove-button clicks or Delete/Backspace within a group; not emitted when disabled |
HuiChipGroup Events
| Event | Parameters | Description |
|---|---|---|
| update:modelValue | (value: ChipGroupValue) | Requests a scalar/null or independent array copy before change. |
| change | (value: ChipGroupValue) | Selection notification; multiple-mode arrays are separate from the update payload. |
HuiChip Slots
| Slot | Scope | Description |
|---|---|---|
| default | - | Chip text, replacing label |
| icon | - | Leading icon content, replacing the icon prop |
| remove | - | Remove-button icon; shown only when removable, defaulting to a close icon |
HuiChipGroup Slots
| Slot | Scope | Description |
|---|---|---|
| default | - | Contains HuiChip components, optionally separated by other elements |
Types
import type {
ChipType,
ChipSize,
ChipProps,
ChipGroupProps,
ChipGroupValue,
ChipGroupOption
} from '@nscode/handy-ui'
type ChipType = 'primary' | 'success' | 'warning' | 'danger' | 'info'
type ChipSize = 'large' | 'default' | 'small'
interface ChipProps {
value?: string | number
label?: string
disabled?: boolean
removable?: boolean
icon?: string
image?: string
type?: ChipType
size?: ChipSize
outline?: boolean
}
type ChipGroupValue = string | number | null | (string | number)[]
interface ChipGroupOption {
label: string
value: string | number
disabled?: boolean
icon?: string
type?: ChipType
}
interface ChipGroupProps {
modelValue?: ChipGroupValue
multiple?: boolean
options?: ChipGroupOption[] | string[] | number[]
validateEvent?: boolean
disabled?: boolean
size?: ChipSize
type?: ChipType
outline?: boolean
}
ChipEmits, ChipGroupEmits, and the injection key chipGroupKey are also exported.