ActionBar
Show selected counts and bulk actions after users select records. Use fixed placement at the viewport bottom or sticky placement inside a container. The toolbar does not move focus or lock scrolling. Handle clear to update selection.
Import
import { HuiActionBar } from '@nscode/handy-ui'
import type {
ActionBarProps,
ActionBarPosition,
ActionBarEmits,
ActionBarInfoSlotProps,
ActionBarSlots
} from '@nscode/handy-ui'
Examples
Table selection and a fixed toolbar
Select table rows or click Select two rows. Tab into the toolbar and press Esc, or click Clear selection, to emit clear. The page records event counts and displays a message. Approval updates row status; ActionBar itself never changes records or selection.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionBar, HuiButton, HuiMessage, HuiSpace, HuiTable } from '@nscode/handy-ui'
const rows = ref([
{ id: 1, name: 'Requirements review', status: 'Pending' },
{ id: 2, name: 'Design approval', status: 'Pending' },
{ id: 3, name: 'Test acceptance', status: 'Pending' }
])
const columns = [
{ prop: 'name', label: 'Task' },
{ prop: 'status', label: 'Status' }
]
const keys = ref<Array<string | number>>([])
const clears = ref(0)
const result = ref('Select rows to use the toolbar at the viewport bottom')
const clear = () => {
keys.value = []
clears.value++
result.value = `Received clear ${clears.value} times; selection cleared`
HuiMessage.info(result.value)
}
const approve = () => {
const count = keys.value.length
rows.value = rows.value.map((row) =>
keys.value.includes(row.id) ? { ...row, status: 'Approved' } : row
)
keys.value = []
result.value = `Approved ${count} items`
HuiMessage.success(result.value)
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="keys = [1, 3]">Select two rows</HuiButton>
<HuiTable
v-model:selected-keys="keys"
:data="rows"
:columns="columns"
selectable
row-key="id"
/>
<span>{{ result }}</span>
<HuiActionBar :count="keys.length" :total="rows.length" @clear="clear">
<HuiButton type="primary" @click="approve">Approve selected</HuiButton>
</HuiActionBar>
</HuiSpace>
</template>
Sticky inside a container
Place the toolbar last in a scrollable card. Its default bottom offset is 0. Scroll the card to inspect its position, and select again after clearing.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionBar, HuiButton, HuiSpace } from '@nscode/handy-ui'
const count = ref(3)
const result = ref('Scroll the card; the toolbar stays at its bottom')
const clear = () => {
count.value = 0
result.value = 'Received clear; selection cleared'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="count = 3">Select three again</HuiButton>
<div class="scroll-card">
<p v-for="index in 14" :key="index">Record {{ index }}: scroll to view the card content.</p>
<HuiActionBar position="sticky" :count="count" :total="14" @clear="clear">
<HuiButton @click="result = `Exported ${count} items`">Export selected</HuiButton>
</HuiActionBar>
</div>
<span>{{ result }}</span>
</HuiSpace>
</template>
<style scoped>
.scroll-card {
height: 240px;
overflow: auto;
padding: var(--hui-spacing-4);
border: var(--hui-border-width) var(--hui-border-style) var(--hui-border-color);
border-radius: var(--hui-border-radius);
}
.scroll-card p {
min-height: 36px;
}
</style>
Explicit visible and reactive count
Without visible, count > 0 controls display. An explicit visible takes precedence: true displays even with count=0, and false hides even with selected items. clear does not set visible to false.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionBar, HuiButton, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
const visible = ref(true)
const count = ref(0)
const result = ref('Explicit visible=true with count=0')
const clear = () => {
count.value = 0
result.value = 'Received clear; visible remains true, so the toolbar stays'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace>
<HuiSwitch v-model="visible" aria-label="Toggle toolbar visibility" />
<span>visible: {{ visible }},count: {{ count }}</span>
<HuiButton @click="count++">Select one more</HuiButton>
</HuiSpace>
<HuiActionBar position="sticky" :visible="visible" :count="count" @clear="clear">
<HuiButton @click="result = `Process ${count} items`">Process selected</HuiButton>
</HuiActionBar>
<span>{{ result }}</span>
</HuiSpace>
</template>
clearable
clearable=false hides the clear button and disables the toolbar's Esc shortcut and instance clear() method. Business action buttons remain usable.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionBar, HuiButton, HuiSpace } from '@nscode/handy-ui'
const flags = [true, false]
const counts = ref([2, 2])
const clears = ref([0, 0])
const clear = (index: number) => {
counts.value[index] = 0
clears.value[index]++
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<div v-for="(flag, index) in flags" :key="String(flag)">
<HuiSpace>
<span>clearable={{ flag }},clear events: {{ clears[index] }}</span>
<HuiButton @click="counts[index] = 2">Select two again</HuiButton>
</HuiSpace>
<HuiActionBar
position="sticky"
:count="counts[index]"
:clearable="flag"
@clear="clear(index)"
>
<HuiButton @click="counts[index]++">Select one more</HuiButton>
</HuiActionBar>
</div>
</HuiSpace>
</template>
Numeric and CSS offsets
Numbers and numeric strings use pixels; other strings are CSS lengths. These sticky examples compare offsets. Fixed placement accepts the same forms. When offset is omitted, changing position also changes the default offset.
<script setup lang="ts">
import { HuiActionBar, HuiButton, HuiSpace } from '@nscode/handy-ui'
const offsets: Array<number | string> = [0, 16, '16', '1rem', 'calc(1rem + 4px)']
</script>
<template>
<HuiSpace direction="vertical" fill>
<div v-for="(offset, index) in offsets" :key="index" class="offset-stage">
<p>offset: {{ JSON.stringify(offset) }}</p>
<div class="filler">Scroll to compare bottom offsets</div>
<HuiActionBar position="sticky" :count="1" :offset="offset" :clearable="false">
<HuiButton>Focusable action</HuiButton>
</HuiActionBar>
</div>
</HuiSpace>
</template>
<style scoped>
.offset-stage {
height: 150px;
overflow: auto;
padding: var(--hui-spacing-3);
border: var(--hui-border-width) var(--hui-border-style) var(--hui-border-color);
}
.filler {
height: 160px;
color: var(--hui-text-color-secondary);
}
</style>
Custom info and actions
The info slot receives the current count and total, replacing the default text. The default slot holds business buttons; the toolbar does not execute bulk actions for them.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionBar, HuiButton, HuiSpace, HuiTag } from '@nscode/handy-ui'
const count = ref(2)
const result = ref('Waiting')
const clear = () => {
count.value = 0
result.value = 'Received clear'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="count = 2">Select two again</HuiButton>
<HuiActionBar position="sticky" :count="count" :total="8" @clear="clear">
<template #info="{ count: selected, total }">
<HuiTag type="warning">Pending {{ selected }} / {{ total }} items</HuiTag>
</template>
<HuiButton type="primary" @click="result = `Scheduled ${count} items`">Schedule</HuiButton>
<HuiButton @click="result = `Exported ${count} items`">Export</HuiButton>
</HuiActionBar>
<span>{{ result }}</span>
</HuiSpace>
</template>
Esc closes an inner popup first
Open the select or popover and press Esc to close that popup first. Esc requests clear when focus is on a regular action button. Esc outside the toolbar and IME composition do not clear selection.
<script setup lang="ts">
import { ref } from 'vue'
import {
HuiActionBar,
HuiButton,
HuiMessage,
HuiPopover,
HuiSelect,
HuiSpace
} from '@nscode/handy-ui'
const count = ref(2)
const mode = ref('review')
const result = ref('Open a popup and press Esc; selection stays')
const clear = () => {
count.value = 0
result.value = 'Toolbar received clear; selection cleared'
HuiMessage.info(result.value)
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="count = 2">Select two again</HuiButton>
<HuiActionBar position="sticky" :count="count" @clear="clear">
<HuiSelect
v-model="mode"
:options="[
{ value: 'review', label: 'Review' },
{ value: 'export', label: 'Export' }
]"
style="width: 140px"
/>
<HuiPopover trigger="click" content="Esc closes only this popover while it is open">
<template #reference><HuiButton>Open details</HuiButton></template>
</HuiPopover>
<HuiButton @click="result = 'Focus is on a regular button; press Esc to clear selection'"
>Regular action</HuiButton
>
</HuiActionBar>
<span>{{ result }}, current mode: {{ mode }}</span>
</HuiSpace>
</template>
Language, local styling and total=0
Built-in text follows ConfigProvider locale. Sticky inherits theme variables from its region. Fixed teleports to body and inherits global variables. Variables on a local ancestor do not cross Teleport; apply them to the toolbar root with class/style.
<script setup lang="ts">
import { ref } from 'vue'
import {
HuiActionBar,
HuiButton,
HuiConfigProvider,
HuiSpace,
localeEn,
localeZhCn
} from '@nscode/handy-ui'
const english = ref(false)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="english = !english">Switch language</HuiButton>
<HuiConfigProvider :locale="english ? localeEn : localeZhCn">
<HuiActionBar
position="sticky"
visible
:count="0"
:total="0"
:clearable="false"
style="--hui-bg-color: var(--hui-fill-color-light)"
>
<HuiButton @click="english = !english">{{
english ? 'Change language' : 'Change language'
}}</HuiButton>
</HuiActionBar>
</HuiConfigProvider>
</HuiSpace>
</template>
clear() and request boundaries
Call clear() through a ref typed as ActionBarExpose. It shares the built-in cancel button's request handler. Calls do nothing while the bar is actually hidden, clearable=false, or after unmount. Explicit visible=true still permits requests when count=0. Calling clear() again from its synchronous listener does not recurse; later independent calls each emit once. This example counts requests without changing selection data.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiActionBar, HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { ActionBarExpose } from '@nscode/handy-ui'
const actionBarRef = ref<ActionBarExpose>()
const count = ref(2)
const visible = ref(true)
const clearable = ref(true)
const requests = ref(0)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace wrap>
<HuiButton @click="actionBarRef?.clear()">Call clear()</HuiButton>
<HuiButton @click="visible = !visible">visible={{ visible }}</HuiButton>
<HuiButton @click="clearable = !clearable">clearable={{ clearable }}</HuiButton>
<HuiButton @click="count = count ? 0 : 2">count={{ count }}</HuiButton>
</HuiSpace>
<HuiActionBar
ref="actionBarRef"
position="sticky"
:visible="visible"
:count="count"
:clearable="clearable"
@clear="requests++"
>
<span>This example counts requests without changing selection data</span>
</HuiActionBar>
<p role="status">clear requests: {{ requests }}; count={{ count }}, visible={{ visible }}</p>
</HuiSpace>
</template>
Props
| Prop | Description | Type | Default |
|---|---|---|---|
| count | Selected count; displays when greater than 0 unless visible is explicit | number | 0 |
| total | Total count; 0 is valid | number | — |
| visible | Explicit display control, taking precedence over count | boolean | — |
| position | Fixed at the viewport bottom, or sticky in its container | ActionBarPosition | 'fixed' |
| offset | Bottom offset; numbers and numeric strings use px, other strings use CSS lengths | number | string | fixed: 24; sticky: 0 |
| clearable | Show the clear button and enable Esc inside the toolbar | boolean | true |
Events
| Event | Arguments | Description |
|---|---|---|
| clear | None | Calling clear(), the clear button, or an unhandled Esc inside the toolbar; update selection in the application |
Slots
| Slot | Arguments | Description |
|---|---|---|
| default | None | Bulk action buttons |
| info | { count: number, total: number | undefined } | Replace visible count text; a separate live region announces localized count and total |
Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
| clear | None | void | Request selection cancellation, just like the cancel button; ignored while actually hidden, clearable=false, or after unmount |
The method only emits clear without arguments. It does not change count, visible, business data, or focus. Explicit visible=true permits a request with count=0; without visible, a nonpositive count hides the bar and requests are ignored.
Types
type ActionBarPosition = 'fixed' | 'sticky'
interface ActionBarProps {
count?: number
total?: number
visible?: boolean
position?: ActionBarPosition
offset?: number | string
clearable?: boolean
}
interface ActionBarEmits {
clear: []
}
interface ActionBarExpose {
clear: () => void
}
interface ActionBarInfoSlotProps {
count: number
total: number | undefined
}
interface ActionBarSlots {
default?: () => unknown
info?: (props: ActionBarInfoSlotProps) => unknown
}