Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Action Bar for Vue UI SDK

A floating action bar for Vue on UI SDK: it rises from the bottom while rows are selected, shows the count and holds the bulk actions.

On this page9 sections

An action bar floats at the bottom of the screen while something is selected, with the number of items picked and the actions that apply to all of them at once. It suits tables, file lists and inboxes, where people tick a few rows and then act on the batch.

Actions that should always be on screen belong in a Button Group, and a few actions on a single row fit in a Dropdown Menu.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Action Bar anatomy: content, value, body, separator, close

Usage

<script setup lang="ts">
import {
  ArchiveIcon, DownloadIcon, PencilIcon, Trash2Icon, XIcon,
} from "lucide-vue-next"
import {
  ActionBar, ActionBarBody, ActionBarButton, ActionBarClose,
  ActionBarContent, ActionBarSeparator, ActionBarTrigger,
  ActionBarValue,
} from "@/components/ui/action-bar"
import { Button } from "@/components/ui/button"
</script>

<template>
  <ActionBar>
    <ActionBarTrigger>
      <template #render="{ props }">
        <Button v-bind="props" variant="outline">Open</Button>
      </template>
    </ActionBarTrigger>
    <ActionBarContent aria-label="Bulk actions">
      <ActionBarValue :count="3" />
      <ActionBarSeparator />
      <ActionBarBody>
        <ActionBarButton>
          <PencilIcon />
          <span class="max-sm:sr-only">Edit</span>
        </ActionBarButton>
        <ActionBarButton>
          <DownloadIcon />
          <span class="max-sm:sr-only">Export</span>
        </ActionBarButton>
        <ActionBarButton>
          <ArchiveIcon />
          <span class="max-sm:sr-only">Archive</span>
        </ActionBarButton>
        <ActionBarSeparator />
        <ActionBarButton variant="destructive">
          <Trash2Icon />
          <span class="max-sm:sr-only">Delete</span>
        </ActionBarButton>
      </ActionBarBody>
      <ActionBarSeparator />
      <ActionBarClose>
        <template #render="{ props }">
          <Button v-bind="props" size="icon-md" variant="ghost"><XIcon /></Button>
        </template>
      </ActionBarClose>
    </ActionBarContent>
  </ActionBar>
</template>

Accessibility

ActionBarContent has the toolbar role and no name of its own, so give it an aria-label that says what the actions apply to, such as "Actions for selected orders". The bar renders in a portal at the end of the page and takes no focus when it opens, so keyboard users reach it by tabbing past the rest of the page. Once focus is inside, the arrow keys move between its buttons. ActionBarValue has the status role, so screen readers announce the count when it changes. A button that hides its text on small screens with max-sm:sr-only keeps that text as its name.

Tab
Moves focus to the next button in the bar. The bar comes after the page's own content in the tab order.
Shift+Tab
Moves focus to the previous button.
Arrow Right
Moves focus to the next button in the bar, and from the last one to the first. In a right-to-left layout it moves the other way.
Arrow Left
Moves focus to the previous button in the bar, and from the first one to the last. In a right-to-left layout it moves the other way.
Home
Moves focus to the first button in the bar.
End
Moves focus to the last button in the bar.
Enter
Presses the focused button.
Space
Presses the focused button.
Escape
Closes the bar from anywhere on the page, unless closeOnEscape is false or a dialog or menu opened from the bar takes the key first.

Demos

Close trigger

The full bar with three items counted, opened from an Open button, with open held in state. Its X is ActionBarClose, a button labeled Close that calls onOpenChange with false, the same call Escape makes, so one handler covers both ways out. Clear the selection in that handler when closing the bar should also let go of the rows.

Preview width

Controlled

There is no ActionBarTrigger here. A Toggle button outside the bar flips open, and onOpenChange reports every close, from the X or from Escape, so your state always matches the screen. This is the shape a real page has, where a selection or other state decides whether the bar shows, while ActionBarTrigger only fits a bar people open on purpose.

Preview width

Custom spacing

ActionBarContent takes its padding from --space, which starts at --spacing(2), and this demo sets it with a class to --spacing(3), so the bar is a little taller and roomier than the default. Set a smaller step for a tight bar over a dense table, or a larger one around big buttons. The count, the actions and the close button all sit inside that one padding.

Preview width

Dialog

The bar holds one action, Delete, and it doesn't run right away: it opens an alert dialog titled Delete selected orders, with Cancel and a destructive Delete. Put a confirmation on any bar action that destroys data or can't be undone. Escape closes the dialog first and leaves the bar open.

Preview width

Gutter

Two buttons open the bar with gutter in positioning set to 24px or 32px, up from the default 16px. The gutter is the space between the bar and the bottom edge, and the bar adds the bottom safe-area inset on top of it, so a phone's home indicator doesn't cover the actions. Raise it when a cookie banner or a player already sits on that edge.

Preview width

The bar's body is one More button that opens a menu upward, holding Archive, Duplicate and a destructive Delete. Put the rare actions in a menu like this when the bar would otherwise run wider than a phone screen, and keep the frequent ones as buttons beside it. The menu opens upward because the bar already sits on the bottom edge.

Preview width

Positioning

Three buttons open the bar at bottom-start, bottom or bottom-end, set through placement in positioning. Centered suits most bulk actions. The corners fit a selection that lives in a sidebar or a narrow pane, where a centered bar would cover the wrong column, and every placement stays on the bottom edge.

Preview width

Table

Five orders with a checkbox on each row and one in the header that selects them all. The bar is open while any are selected and shows the count, Send, Edit, a More menu and Delete, which confirms in a dialog listing the chosen orders. Closing the bar clears the selection, and this is the wiring to copy into a real list.

Preview width

FAQ

When should I use an Action Bar instead of a toolbar or a menu?

Use an Action Bar for actions on a selection. It appears when the first item is picked, floats over the page so it's in reach wherever the list scrolls, and goes away when the selection clears, as in the Table demo.

Actions that are always available belong in a Button Group in the page itself. For a few actions on one item, put a Dropdown Menu on that row instead.

How do I show the Action Bar when rows are selected in Vue?

Drive it from your selection state rather than a trigger. Bind :open to whether anything is selected, such as selected.length > 0, and clear the selection in @open-change when it receives false.

The bar then shows with the first checked row and hides when the last one is unchecked, and the X and Escape clear the rows too. The Table demo wires it this way with checkboxes.

How do I show how many items are selected in the Action Bar?

Add an ActionBarValue with count set to the number of selected items. It renders the number in a secondary badge, with tabular figures so the width doesn't jump as the count changes.

Pass label or children to show words instead, such as 3 selected, and set variant, size or pill to restyle the badge, since it takes the same props as Badge.

How do I change where the Action Bar appears on the screen?

Pass positioning to ActionBar. Its placement is bottom, bottom-start or bottom-end, and its gutter is the distance from the bottom edge as a CSS length, 16px unless you set another, as the Positioning and Gutter demos show.

The bar always sits on the bottom edge, with no top placement. It adds the bottom safe-area inset to the gutter, so on a phone it clears the home indicator.

How do I stop the Action Bar from covering the last rows of my table?

Leave room for it at the bottom of the page while it's open. The bar is fixed to the bottom of the viewport, so when the list ends at the bottom of the page its last rows can sit underneath it.

Add bottom padding to the list or the page while the selection isn't empty, a little more than the bar's height plus the gutter. With the room there, people can scroll the last row above the bar and still tick it.

Does the Action Bar close when I press Escape?

Yes, from anywhere on the page, and it calls onOpenChange with false as the X does. Set closeOnEscape to false to keep it open until the selection is cleared, for example when Escape already clears a search field above the list.

A dialog or menu opened from the bar takes the key first: Escape closes it and leaves the bar where it was, as the Dialog demo shows.

Is the Action Bar accessible to screen readers and keyboard users?

It's a toolbar, so give ActionBarContent an aria-label that names the selection, such as "Actions for selected orders", and once focus is inside, the arrow keys move between its buttons. ActionBarValue has the status role, so screen readers announce the count as it changes. Icon buttons can hide their text on small screens with max-sm:sr-only and keep it as their name.

One thing is left to you. The bar takes no focus when it opens and sits at the end of the tab order, so keyboard users tab past the rest of the page to reach it. Give them a shortcut that moves focus into the bar, or a skip link beside the list.

Can I open a confirmation dialog or a menu from the Action Bar?

Yes. Put the dialog or menu trigger inside ActionBarBody like any other button. The Dialog demo confirms a delete before it runs, and the Menu demo moves the rare actions behind a More button so the bar stays short on a phone.

Open menus upward, since the bar is already on the bottom edge. Both close on Escape before the bar does, so dismissing one leaves the selection alone.

API Reference

ActionBar

PropType
open?boolean

The open state of the action bar. Two-way with v-model or v-model:open.

defaultOpen?boolean

The default open state of the action bar.

Default
false
closeOnEscape?boolean

Whether to close the action bar when the Escape key is pressed.

Default
true
lazyMount?boolean

Whether to lazy mount the action bar.

Default
true
positioning?object

Placement and gutter of the action bar.

Type
{ gutter?: string; placement?: "bottom" | "bottom-start" | "bottom-end" }
unmountOnExit?boolean

Whether to unmount the action bar once it has closed.

Default
true
EventType
@open-change(open: boolean) → void

The function to call when the open state of the action bar changes.

Parameters

open – boolean

Returns
void

ActionBarTrigger

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

CSS variableType
--gutterstring

ActionBarContent

<div> data-slot="toolbar"

PropType
controller?{ focus: () → void; }

Focuses the toolbar from anywhere. Create one with createToolbarController().

debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Stops every item from being used. Items stay focusable with aria-disabled, so the toolbar keeps its tab stop and stays discoverable.

Default
false
loop?boolean

Whether arrow keys wrap from the last item to the first.

Default
true
orientation?ToolbarOrientation

Which arrow keys move between items: left and right, or up and down.

Default
"horizontal"
placement?"bottom" | "bottom-end" | "bottom-start"

Where it sits at the bottom of the screen: bottom, bottom-start or bottom-end.

Type
"bottom" | "bottom-end" | "bottom-start"
Default
"bottom"
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled, by the item itself, its group or the toolbar.

data-orientation"horizontal" | "vertical"

The toolbar's orientation. On a separator, which way the line runs: across the toolbar.

Type
"horizontal" | "vertical"
CSS variableType
--spacestring

ActionBarButton

<button> data-slot="toolbar-button"

PropType
disabled?boolean

Stops the item from being used. It stays focusable with aria-disabled, so arrow keys still reach it and a tooltip can say why.

Default
false
focusableWhenDisabled?boolean

Whether a disabled item stays reachable with arrow keys. Turn it off to skip it, natively disabled.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled, by the item itself, its group or the toolbar.

data-orientation"horizontal" | "vertical"

The toolbar's orientation. On a separator, which way the line runs: across the toolbar.

Type
"horizontal" | "vertical"
data-size?string

Mirrors size.

data-variant?string

Mirrors variant.

ActionBarSeparator

PropType
debug?boolean

Logs every state change with its reason to the console, in development builds.

decorative?boolean

Hides the separator from assistive technology with role="none", for a line that's only visual. Leave it off when the separator divides content a screen reader should hear as separate, like groups of menu items.

Default
false
orientation?SeparatorOrientation

Which way the line runs. A vertical separator divides items in a row. Separator's default: horizontal.

Default
vertical
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

ActionBarClose

<button> data-slot="toolbar-button"

PropType
disabled?boolean

Stops the item from being used. It stays focusable with aria-disabled, so arrow keys still reach it and a tooltip can say why.

Default
false
focusableWhenDisabled?boolean

Whether a disabled item stays reachable with arrow keys. Turn it off to skip it, natively disabled.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled, by the item itself, its group or the toolbar.

data-orientation"horizontal" | "vertical"

The toolbar's orientation. On a separator, which way the line runs: across the toolbar.

Type
"horizontal" | "vertical"

ActionBarValue

data-slot="action-bar-value"

PropType
countnumber

The number of items selected.

Default
0
label?string

The label of the selection trigger.

pill?boolean

Fully rounded corners.

size?"lg" | "md" | "sm"

The size.

Type
"lg" | "md" | "sm"
variant?"default" | "destructive" | "ghost" | "info" | "link" | "outline" | "secondary" | "success" | "warning"

Badge's default: default.

Type
"default" | "destructive" | "ghost" | "info" | "link" | "outline" | "secondary" | "success" | "warning"
Default
secondary
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

ActionBarBody

PropType
class?string

Merged with the part's classes.