ActionGroup
A row of action buttons occupying up to max positions, with overflow actions placed in a More dropdown. More displays text by default; more-display can show the number of overflow actions or use an icon. This is useful in a table's action column: pass each row as row to control action visibility and availability from that row's data.
Import
import { HuiActionGroup } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
Basic Usage
actions is an array of action items, each with at least a key and label. Clicking an action emits actionClick with the action item and row.
<script setup lang="ts">
import { HuiActionGroup, HuiMessage } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'View', icon: 'eye' },
{ key: 'edit', label: 'Edit', icon: 'edit' },
{ key: 'copy', label: 'Copy', icon: 'copy' },
{ key: 'delete', label: 'Delete', icon: 'trash', type: 'danger' }
]
const onAction = (action: ActionGroupItem) => {
HuiMessage(`Clicked ${action.label}`)
}
</script>
<template>
<HuiActionGroup :actions="actions" @action-click="onAction" />
</template>
Maximum Visible Positions
max defaults to 3, and More occupies one position:
- When the number of visible actions does not exceed
max, all actions are shown directly and More is omitted. - Otherwise, the first
max - 1actions are shown directly and the rest go into More. The dropdown therefore contains at least two items; it is never created for only one overflow action.
| Visible actions | max | Shown directly | Inside More |
|---|---|---|---|
| 3 | 3 | 3 items | - |
| 4 | 3 | 2 items | 2 items |
| 5 | 2 | 1 items | 4 items |
| 5 | 1 | - | 5 items |
Fractional max values are rounded down. Values below 1 (0, negative values, or NaN) are treated as 1 and produce a console warning. Infinity shows all actions directly. Each row below uses the same five actions, with its max value shown first:
<script setup lang="ts">
import { HuiActionGroup, HuiSpace } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'View' },
{ key: 'edit', label: 'Edit' },
{ key: 'copy', label: 'Copy' },
{ key: 'export', label: 'Export' },
{ key: 'delete', label: 'Delete', type: 'danger' }
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace>
<span class="row-label">1</span>
<HuiActionGroup :actions="actions" :max="1" />
</HuiSpace>
<HuiSpace>
<span class="row-label">2</span>
<HuiActionGroup :actions="actions" :max="2" />
</HuiSpace>
<HuiSpace>
<span class="row-label">3(Default)</span>
<HuiActionGroup :actions="actions" />
</HuiSpace>
<HuiSpace>
<span class="row-label">4</span>
<HuiActionGroup :actions="actions" :max="4" />
</HuiSpace>
<HuiSpace>
<span class="row-label">5</span>
<HuiActionGroup :actions="actions" :max="5" />
</HuiSpace>
<HuiSpace>
<span class="row-label">Infinity</span>
<HuiActionGroup :actions="actions" :max="Infinity" />
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 72px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Row-Based Visibility and Disabled State
visible and disabled accept a boolean or a function receiving row. Actions are filtered by visible before max determines the overflow items. Hidden actions do not occupy a position.
With ActionGroupItem<User>[], the callback's row is typed as User.
<script setup lang="ts">
import { HuiActionGroup } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
interface User {
id: number
name: string
status: 'active' | 'locked'
}
defineProps<{ user: User }>()
const actions: ActionGroupItem<User>[] = [
{ key: 'edit', label: 'Edit' },
{ key: 'lock', label: 'Lock', visible: (row) => row.status === 'active' },
{ key: 'unlock', label: 'Unlock', visible: (row) => row.status === 'locked' },
{ key: 'delete', label: 'Delete', type: 'danger', disabled: (row) => row.status === 'locked' }
]
</script>
<template>
<HuiActionGroup :actions="actions" :row="user" />
</template>
Each row below represents a user. Active users can be locked; locked users can be unlocked but cannot use Delete. Export is hidden for everyone (visible: false) and occupies no position. Clicking Lock or Unlock changes that row's status.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionGroup, HuiSpace, HuiTag } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
interface User {
id: number
name: string
status: 'active' | 'locked'
}
const users = ref<User[]>([
{ id: 1, name: '张三', status: 'active' },
{ id: 2, name: '李四', status: 'locked' }
])
const actions: ActionGroupItem<User>[] = [
{ key: 'edit', label: 'Edit' },
{
key: 'lock',
label: 'Lock',
visible: (row) => row.status === 'active',
onClick: (row) => {
row.status = 'locked'
}
},
{
key: 'unlock',
label: 'Unlock',
visible: (row) => row.status === 'locked',
onClick: (row) => {
row.status = 'active'
}
},
{ key: 'export', label: 'Export', visible: false },
{ key: 'delete', label: 'Delete', type: 'danger', disabled: (row) => row.status === 'locked' }
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace v-for="user in users" :key="user.id">
<span>{{ user.name }}</span>
<HuiTag :type="user.status === 'active' ? 'success' : 'warning'" size="small">
{{ user.status === 'active' ? 'Active' : 'Locked' }}
</HuiTag>
<HuiActionGroup :actions="actions" :row="user" />
</HuiSpace>
</HuiSpace>
</template>
Table Action Columns
Use the component in the table's action-column slot and pass the current row. size="small" is commonly used to match a small table.
The buttons use HuiButton with variant="link" and no horizontal padding. They have no background or border, and only fade on hover, avoiding an additional background over the hovered table row. Text aligns with the cell's left edge, and spacing between buttons is 16 / 12 / 8px according to size.
<script setup lang="ts">
import { HuiTable, HuiActionGroup, HuiMessage } from '@nscode/handy-ui'
import type { ActionGroupItem, TableColumnConfig } from '@nscode/handy-ui'
const columns: TableColumnConfig[] = [
{ prop: 'name', label: 'Name' },
{ prop: 'action', label: 'Actions', width: 200 }
]
const data = [
{ id: 1, name: '张三' },
{ id: 2, name: '李四' }
]
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'View' },
{ key: 'edit', label: 'Edit' },
{ key: 'copy', label: 'Copy' },
{ key: 'delete', label: 'Delete', type: 'danger' }
]
const onAction = (action: ActionGroupItem, row: Record<string, unknown>) => {
HuiMessage(`Row ${row.id}: ${action.label}`)
}
</script>
<template>
<HuiTable :data="data" :columns="columns" size="small">
<template #action="{ row }">
<HuiActionGroup :actions="actions" :row="row" size="small" @action-click="onAction" />
</template>
</HuiTable>
</template>
Per-Action Click Callbacks
An item's onClick(row) runs after the actionClick event. Use either approach or both: onClick keeps logic with each action, while actionClick allows centralized dispatch by key.
<script setup lang="ts">
import { HuiActionGroup } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
interface User {
id: number
name: string
}
defineProps<{ user: User }>()
const openEditor = (row: User) => console.log('Edit', row.id)
const confirmDelete = (row: User) => console.log('Delete', row.id)
const actions: ActionGroupItem<User>[] = [
{ key: 'edit', label: 'Edit', onClick: (row) => openEditor(row) },
{ key: 'delete', label: 'Delete', type: 'danger', onClick: (row) => confirmDelete(row) }
]
</script>
<template>
<HuiActionGroup :actions="actions" :row="user" />
</template>
Click an action below to see the order when both are used:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionGroup } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
interface User {
id: number
name: string
}
const user: User = { id: 7, name: '王五' }
const logs = ref<string[]>([])
const actions: ActionGroupItem<User>[] = [
{ key: 'edit', label: 'Edit', onClick: (row) => logs.value.push(`onClick: Edit ${row.name}`) },
{
key: 'delete',
label: 'Delete',
type: 'danger',
onClick: (row) => logs.value.push(`onClick: Delete ${row.name}`)
}
]
const onAction = (action: ActionGroupItem, row: User) => {
logs.value = [`actionClick: ${action.key}, row.id = ${row.id}`]
}
</script>
<template>
<HuiActionGroup :actions="actions" :row="user" @action-click="onAction" />
<p style="margin-top: 12px">{{ logs.length ? logs.join(' → ') : 'No clicks yet' }}</p>
</template>
Button Types, Icons, and More Display
typeis the button type, defaulting toprimary(primary-colored text). AllHuiButtontypes are supported. In More, onlydangerchanges the menu item's text to the danger color, such as Delete; other types use the regular menu-item appearance.iconis an icon name supported byHuiIcon(see the Icons guide). It appears before the button text, or before the menu-item text in More.
<script setup lang="ts">
import { HuiActionGroup } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'Default type', icon: 'eye', type: 'default' },
{ key: 'edit', label: 'Primary', icon: 'edit' },
{ key: 'pass', label: 'Success', icon: 'check', type: 'success' },
{ key: 'warn', label: 'Warning', icon: 'warning', type: 'warning' },
{ key: 'info', label: 'Info', icon: 'info', type: 'info' },
{ key: 'help', label: 'Help', icon: 'help', type: 'help' },
{ key: 'copy', label: 'Copy', icon: 'copy', type: 'success' },
{ key: 'delete', label: 'Delete', icon: 'trash', type: 'danger' }
]
</script>
<template>
<HuiActionGroup :actions="actions" :max="7" />
</template>
more-display controls the More button's appearance and defaults to text:
text: themore-textlabel (localized by default, such as More in English) followed by a downward arrow. The arrow points up while the menu is open. No count is shown.text-count: the label, an overflow count on a lightly shaded rounded background, and a downward arrow.count: a lightly shaded pill showing+N, with a primary-colored border on hover or while the menu is open.icon: only the horizontal ellipsis icon (more-horizontal), suitable for narrow table action columns.
N is the number of overflow actions in the menu; hidden actions (visible: false) are excluded. The last three styles use more-text plus the count as their accessible name, such as More 2. Each row below demonstrates a style:
<script setup lang="ts">
import { HuiActionGroup, HuiSpace } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'View', icon: 'eye' },
{ key: 'edit', label: 'Edit', icon: 'edit' },
{ key: 'copy', label: 'Copy', icon: 'copy' },
{ key: 'delete', label: 'Delete', icon: 'trash', type: 'danger' }
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace>
<span class="row-label">text</span>
<HuiActionGroup :actions="actions" more-display="text" />
</HuiSpace>
<HuiSpace>
<span class="row-label">text-count</span>
<HuiActionGroup :actions="actions" more-display="text-count" />
</HuiSpace>
<HuiSpace>
<span class="row-label">count</span>
<HuiActionGroup :actions="actions" more-display="count" />
</HuiSpace>
<HuiSpace>
<span class="row-label">icon</span>
<HuiActionGroup :actions="actions" more-display="icon" />
</HuiSpace>
<HuiSpace>
<span class="row-label">more-text</span>
<HuiActionGroup :actions="actions" more-text="More" />
<HuiActionGroup :actions="actions" more-display="text-count" more-text="More" />
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 80px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Triggers
trigger controls how the More dropdown opens: hover (the default, also allowing a click to open it) or click (click to open, then click again to close).
<script setup lang="ts">
import { HuiActionGroup, HuiSpace } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'View' },
{ key: 'edit', label: 'Edit' },
{ key: 'copy', label: 'Copy' },
{ key: 'delete', label: 'Delete', type: 'danger' }
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace>
<span class="row-label">hover</span>
<HuiActionGroup :actions="actions" trigger="hover" more-text="Open on hover" />
</HuiSpace>
<HuiSpace>
<span class="row-label">click</span>
<HuiActionGroup :actions="actions" trigger="click" more-text="Open on click" />
</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, or small: button heights are 40 / 32 / 24px, font sizes 16 / 14 / 12px, icon sizes 18 / 16 / 14px, and gaps 16 / 12 / 8px. More menu items also follow the size (row heights of 40 / approximately 36 / 28px, and font sizes of 16 / 14 / 12px). When omitted, the component follows HuiConfigProvider.size, falling back to default.
<script setup lang="ts">
import { HuiActionGroup, HuiSpace } from '@nscode/handy-ui'
import type { ActionGroupItem } from '@nscode/handy-ui'
const actions: ActionGroupItem[] = [
{ key: 'view', label: 'View', icon: 'eye' },
{ key: 'edit', label: 'Edit', icon: 'edit' },
{ key: 'copy', label: 'Copy', icon: 'copy' },
{ key: 'delete', label: 'Delete', icon: 'trash', type: 'danger' }
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace>
<span class="row-label">large</span>
<HuiActionGroup :actions="actions" size="large" />
<HuiActionGroup :actions="actions" size="large" more-display="count" />
</HuiSpace>
<HuiSpace>
<span class="row-label">default</span>
<HuiActionGroup :actions="actions" />
<HuiActionGroup :actions="actions" more-display="count" />
</HuiSpace>
<HuiSpace>
<span class="row-label">small</span>
<HuiActionGroup :actions="actions" size="small" />
<HuiActionGroup :actions="actions" size="small" more-display="count" />
</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>
Keyboard Interaction
- Tab focuses each button, skipping disabled buttons. Enter or Space activates it.
- On More, Enter, Space, or ArrowDown opens the menu and focuses its first available item. ArrowUp/ArrowDown move between items, Home/End go to the first/last item, and Enter/Space select an item.
- Esc or selecting an item closes the menu and returns focus to More.
Props
| Prop | Type | Default value | Description |
|---|---|---|---|
| actions | ActionGroupItem[] | [] | Action items; see ActionGroupItem below |
| max | number | 3 | Maximum number of positions, including More. Overflow shows the first max - 1 actions directly and places the rest in More; values below 1 are treated as 1 |
| row | any | - | Current row, passed unchanged to disabled, visible, onClick, and the actionClick event |
| moreText | string | Localized (English: More) | More button label. When moreDisplay is not text, the label plus the count forms the accessible name, such as More 2 |
| moreDisplay | 'text' | 'text-count' | 'count' | 'icon' | 'text' | More appearance: text with an arrow, text with a count, a +N pill, or an ellipsis icon. The count excludes hidden actions |
| trigger | 'hover' | 'click' | 'hover' | Trigger for the More dropdown |
| size | 'large' | 'default' | 'small' | - | Size. Follows HuiConfigProvider.size when omitted, otherwise falls back to 'default'; tables commonly use small |
ActionGroupItem
| Prop | Type | Default value | Description |
|---|---|---|---|
| key | string | - | Required unique identifier |
| label | string | - | Required button text, also used as its accessible name |
| icon | string | - | Icon name |
| type | ButtonType | 'primary' | Button type; in More, only danger changes the menu-item text color |
| disabled | boolean | ((row) => boolean) | false | Whether disabled. Disabled actions emit no event and do not call onClick |
| visible | boolean | ((row) => boolean) | true | Whether visible. Filtering occurs before calculating max |
| onClick | (row) => void | - | Called on click, after the actionClick event |
Events
The declared and emitted event name is actionClick; the old name is not emitted as a second event. Vue templates should use @action-click (resolved by the compiler to the camelCase listener), and render functions use onActionClick. The raw JavaScript key 'onAction-click' is not a compatibility alias for the new declaration. The action item, row argument, and event-before-onClick order are preserved.
| Event | Callback arguments | Description |
|---|---|---|
| actionClick | (action: ActionGroupItem, row: any) | Emitted when a direct button or a More menu item is clicked; @actionClick also works in templates |
Slots
There are no slots. Buttons are generated from actions; compose HuiButton and HuiDropdown directly for fully custom buttons.
Methods
No public methods are exposed.
Types
Public types use the component prefix. Compatibility mappings are ActionRow → ActionGroupRow and ActionItem → ActionGroupItem. The old names remain importable from @nscode/handy-ui, are marked @deprecated, and will be removed in 1.0.
import type {
ActionGroupProps,
ActionGroupEmits,
ActionGroupSize,
ActionGroupMoreDisplay,
ActionGroupTrigger,
ActionGroupItem,
ActionGroupRow
} from '@nscode/handy-ui'
type ActionGroupSize = 'large' | 'default' | 'small'
type ActionGroupMoreDisplay = 'text' | 'text-count' | 'count' | 'icon'
type ActionGroupTrigger = 'hover' | 'click'
/** Row data; its type is unrestricted because the component does not read its fields */
type ActionGroupRow = any
interface ActionGroupItem<R = ActionGroupRow> {
key: string
label: string
icon?: HuiIconName
type?: ButtonType
disabled?: boolean | ((row: R) => boolean)
visible?: boolean | ((row: R) => boolean)
onClick?: (row: R) => void
}
interface ActionGroupProps {
actions?: ActionGroupItem[]
max?: number
row?: ActionGroupRow
moreText?: string
moreDisplay?: ActionGroupMoreDisplay
trigger?: ActionGroupTrigger
size?: ActionGroupSize
}
interface ActionGroupEmits {
actionClick: [action: ActionGroupItem, row: ActionGroupRow]
}