Selection alert
VTableSelectionAlert shares the controlled selectedRowKeys with the table. It shows the count based on the keys and provides a clear control and a slot for application actions. You can place it above the table, in the toolbar extension row or in a pagination content slot.
Cross-page batch actions
The example below simulates remote pagination with two pages of data. Check records on both pages and you will see that the selected count includes records that are not currently loaded, while selectedRows in the slot contains only the loaded records passed in by the application. Batch actions use the keys and do not depend on whether the current page's data is complete.
The alert counts controlled selectedRowKeys, so it can show keys retained by application code across pages even without preserve enabled on the table. Set preserveSelectedRowKeys: true on the table if its selection callbacks need to return selected records from earlier pages. The alert slot's selectedRows comes from the alert's prop of the same name; it does not automatically read the table's record cache. Application code can pass the selected rows returned by table callbacks to the alert. If selectedRows is omitted, the slot receives an empty array. See Pagination and cross-page selection.
The alert never requests other pages on its own, and it does not turn "all loaded records selected" into "all results on the server". If your application needs to act on every result of a query, define a separate server-side selection protocol.
Controlled state and clearing
<VTableSelectionAlert
v-model:selected-row-keys="selectedRowKeys"
:selected-rows="availableSelectedRows"
:loading="batchLoading"
@clear="handleClear"
>
<template #actions="{ selectedRowKeys, disabled }">
<a-button :disabled="disabled" @click="approve(selectedRowKeys)">Batch approve</a-button>
</template>
</VTableSelectionAlert>Clearing emits update:selectedRowKeys([]) and then clear(previousKeys, availableRows). Until the parent accepts the update, the displayed count stays at the value passed in. The component does not keep a second copy of the selection state, and it triggers neither the table's change event nor a refresh request.
disabled or loading disables the default clear control, and disabled in the slot reflects both states. Application buttons bind that value themselves. By default the whole alert is hidden when nothing is selected; alwaysShow displays the zero-selection state, in which the clear button is disabled.
Visibility transitions
The alert uses a height expansion or collapse with a fade lasting about 180ms by default. Its height follows the actual content, including wrapped text and buttons; once the leave transition finishes, the alert no longer occupies space. Transitions run only when the alert changes between hidden and visible. Changes to the selected count update the content without replaying the transition.
If the alert needs spacing after toolbar buttons, place that spacing inside the alert's collapsible region so it disappears together with the alert:
<VTableSelectionAlert
v-model:selected-row-keys="selectedRowKeys"
style="--vtg-selection-alert-spacing-before: 16px"
/>Use --vtg-selection-alert-motion-duration to adjust the duration; set it to 0s to disable transitions. The component also respects the system's reduced-motion preference. alwaysShow keeps the alert visible, so clearing the selection does not collapse it.
API
TRecord is the application row type.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
selectedRowKeys | readonly Key[] | Required | Controlled selected keys; the count is computed from them alone. Use with v-model:selected-row-keys. |
selectedRows | readonly TRecord[] | [] | Selected records the application currently holds; may be fewer than the keys. |
alwaysShow | boolean | false | Keep the alert visible when nothing is selected. |
showClear | boolean | true | Whether to show the default clear action. |
disabled | boolean | false | Disable built-in actions and pass the disabled state to application slots. |
loading | boolean | false | Loading state of the batch action; also disables clearing. |
locale | object | - | Per-instance text overrides; fields are listed in Themes and locales. |
ui | object | - | Per-instance slot class overrides; available slots are listed in ui slots. |
class | string | - | Class for the root element. |
Events
| Event | Payload | Description |
|---|---|---|
update:selectedRowKeys | (keys: Key[]) => void | Requests an update of the selected keys; the payload is [] when clearing. |
clear | (selectedRowKeys: readonly Key[], selectedRows: readonly TRecord[]) => void | Emitted after clear is clicked; the payload holds the keys and available records from before clearing. |
Slots
The default clear control governed by showClear sits in the action area on the right, together with actions.
| Slot | Payload type | Description |
|---|---|---|
info | TableSelectionAlertSlotProps<TRecord> | Replaces the count text on the left. |
actions | TableSelectionAlertSlotProps<TRecord> | Application actions on the right, next to the default clear action. |
Slot Props
Both info and actions receive TableSelectionAlertSlotProps<TRecord>.
| Field | Type | Description |
|---|---|---|
selectedRowKeys | readonly Key[] | Snapshot of the selected keys. |
selectedRows | readonly TRecord[] | Snapshot of the available records. |
count | number | Number of keys. |
disabled | boolean | disabled || loading. |
loading | boolean | Current loading state. |
clear | () => void | The same controlled update request as the default clear action. |
VTable row selection options
| Prop | Type | Default | Description |
|---|---|---|---|
rowSelection | RowSelection<TRecord> | - | Enables the row selection column; for its fields, see Row selection · RowSelection. |
Themes and locales
Use theme.selectionAlert.slots globally and ui per instance.
The text follows the global locale and supports localeOverrides.selectionAlert and the per-instance locale. {count} in the selected text is replaced with the selected count, label is the name of the region and clear is the text of the clear button.
The classes and CSS variables below control the layout, text and clear control of the alert.
ui slots
| Theme config | Slot | Description |
|---|---|---|
theme.selectionAlert | wrapper | Outer container for visibility transitions and height collapse. |
theme.selectionAlert | content | Content container including the spacing before the alert. |
theme.selectionAlert | root | Visual container of the selection alert. |
theme.selectionAlert | info | Container for the selected count or custom #info content. |
theme.selectionAlert | text | Default selected count text. |
theme.selectionAlert | clear | Clear selection button. |
theme.selectionAlert | option | Container for the clear selection and batch action areas. |
theme.selectionAlert | actions | Batch action content container. |
Preset defaults
createVTableGuild({
theme: {
selectionAlert: {
slots: {
wrapper: '',
content: '',
root: 'box-border flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-[var(--vtg-selection-alert-radius,6px)] bg-[color:var(--vtg-selection-alert-bg,#fafafa)] px-[var(--vtg-selection-alert-padding-inline,24px)] py-[var(--vtg-selection-alert-padding-block,8px)] text-[length:var(--vtg-table-font-size)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)] text-[color:var(--color-muted)]',
info: 'flex min-w-0 flex-1 flex-wrap items-center',
text: 'break-words',
clear: 'shrink-0 border-0 bg-transparent p-0 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-primary)] cursor-pointer hover:text-[color:var(--color-primary-hover)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
option: 'flex min-w-[48px] items-center gap-2 pl-4',
actions: 'flex min-w-0 flex-wrap items-center gap-2',
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
selectionAlert: {
slots: {
wrapper: '',
content: '',
root: 'box-border flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-[var(--vtg-selection-alert-radius,6px)] bg-[color:var(--vtg-selection-alert-bg,#fafafa)] px-[var(--vtg-selection-alert-padding-inline,24px)] py-[var(--vtg-selection-alert-padding-block,8px)] text-[length:var(--vtg-table-font-size)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)] text-[color:var(--color-muted)] rounded-[var(--vtg-selection-alert-radius,4px)]',
info: 'flex min-w-0 flex-1 flex-wrap items-center',
text: 'break-words',
clear: 'shrink-0 border-0 bg-transparent p-0 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-primary)] cursor-pointer hover:text-[color:var(--color-primary-hover)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
option: 'flex min-w-[48px] items-center gap-2 pl-4',
actions: 'flex min-w-0 flex-wrap items-center gap-2 [&>.el-button+.el-button]:!ml-0',
},
},
},
})CSS variables
| Variable | Purpose | antdv | element-plus |
|---|---|---|---|
--color-primary | Theme primary color, used for drag handle hover, button highlights, field states and more | #1677ff | #409eff |
--vtg-selection-alert-radius | Selection alert radius | 6px | 4px |
--vtg-selection-alert-bg | Selection alert background | rgb(0 0 0 / 2%) | #fafafa |
--vtg-selection-alert-padding-inline | Selection alert horizontal padding | 24px | 24px |
--vtg-selection-alert-padding-block | Selection alert vertical padding | 8px | 8px |
--vtg-selection-alert-motion-duration | Transition duration of the alert height and opacity; set to 0s to disable transitions | undeclared, falls back to 180ms | undeclared, falls back to 180ms |
--vtg-selection-alert-motion-easing | Easing curve of the alert visibility transition | undeclared, falls back to cubic-bezier(0.645, 0.045, 0.355, 1) | undeclared, falls back to cubic-bezier(0.645, 0.045, 0.355, 1) |
--vtg-selection-alert-spacing-before | Spacing before the alert, included in its expanded and collapsed height | undeclared, falls back to 0 | undeclared, falls back to 0 |
Type Declarations
Selection alert types
import type { VNodeChild } from 'vue'
import type {
Key,
SlotProps,
SelectionAlertThemeConfig,
VTableGuildSelectionAlertLocale,
} from '@vtable-guild/vtable-guild'
export interface TableSelectionAlertProps<TRecord extends object = Record<string, unknown>> {
selectedRowKeys: readonly Key[]
selectedRows?: readonly TRecord[]
alwaysShow?: boolean
disabled?: boolean
loading?: boolean
showClear?: boolean
locale?: Partial<VTableGuildSelectionAlertLocale>
ui?: SlotProps<SelectionAlertThemeConfig>
class?: string
}
export interface TableSelectionAlertSlotProps<TRecord extends object = Record<string, unknown>> {
selectedRowKeys: readonly Key[]
selectedRows: readonly TRecord[]
count: number
disabled: boolean
loading: boolean
clear: () => void
}
export interface TableSelectionAlertSlots<TRecord extends object = Record<string, unknown>> {
info?: (props: TableSelectionAlertSlotProps<TRecord>) => VNodeChild
actions?: (props: TableSelectionAlertSlotProps<TRecord>) => VNodeChild
}export interface VTableGuildSelectionAlertLocale {
label: string
selected: string
clear: string
}export type SelectionAlertThemeConfig = typeof selectionAlertTheme
export type SelectionAlertSlots = keyof SelectionAlertThemeConfig['slots']
export type QueryThemeConfig = typeof queryTheme
export type QuerySlots = keyof QueryThemeConfig['slots']