Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Action Bar for React and Tailwind

Display an action bar for selected items.

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

Installation

bunx --bun shadcn@latest add https://kit.dev/r/action-bar.json

Anatomy

ActionBar is a React context provider. It does not render a DOM node.

ActionBar
├── ActionBarTrigger
└── ActionBarContent (portaled)
    ├── ActionBarValue
    ├── ActionBarSeparator
    ├── ActionBarBody
    │   └── actions (Button, Menu, …)
    ├── ActionBarSeparator
    └── ActionBarClose

Usage

import {
  ArchiveIcon,
  DownloadIcon,
  PencilIcon,
  Trash2Icon,
  XIcon,
} from "lucide-react";
import {
  ActionBar,
  ActionBarBody,
  ActionBarClose,
  ActionBarContent,
  ActionBarSeparator,
  ActionBarTrigger,
  ActionBarValue,
} from "@/components/ui/action-bar";
import { Button } from "@/components/ui/button";
<ActionBar>
  <ActionBarTrigger asChild>
    <Button variant="outline">Open</Button>
  </ActionBarTrigger>
  <ActionBarContent>
    <ActionBarValue count={3} />
    <ActionBarSeparator />
    <ActionBarBody>
      <Button variant="ghost">
        <PencilIcon />
        <span className="max-sm:sr-only">Edit</span>
      </Button>
      <ActionBarSeparator />
      <Button variant="destructive">
        <Trash2Icon />
        <span className="max-sm:sr-only">Delete</span>
      </Button>
    </ActionBarBody>
    <ActionBarSeparator />
    <ActionBarClose asChild>
      <Button size="icon-md" variant="ghost">
        <XIcon />
      </Button>
    </ActionBarClose>
  </ActionBarContent>
</ActionBar>

Controlled

Use open and onOpenChange to control visibility. ActionBarTrigger only opens the bar; close it with ActionBarClose, Escape, or by setting open to false.

Examples

Positioning

Use the positioning.placement prop to position the action bar.

Gutter

Use positioning.gutter to control the distance from the bottom edge.

Close Trigger

With Dialog

With Menu

Table

Custom Spacing

The [--space:--spacing("value")] on ActionBarContent controls the internal spacing.

Default spacing is --spacing(2).

You can use breakpoint utilities to change the internal spacing at different screen sizes.

md:[--space:--spacing(6)] lg:[--space:--spacing(8)]

API Reference

asChild merges props onto a single child element.

ActionBar

Root provider. Renders no DOM node. Holds open state and positioning.

PropTypeDefaultDescription
openboolean-Controlled open state.
defaultOpenbooleanfalseUncontrolled initial open state.
onOpenChange(open: boolean) => void-Called when the bar opens (true) or closes (false).
closeOnEscapebooleantrueClose when Escape is pressed. Ignored if the event is already defaultPrevented.
lazyMountbooleantrueMount content only after the bar first opens.
unmountOnExitbooleantrueUnmount content after the exit animation.
positioningActionBarPositioning{ placement: "bottom", gutter: "16px" }Placement and offset from the viewport edge.
childrenReactNode-Trigger, content, and other descendants.

positioning

PropTypeDefaultDescription
placement"bottom" | "bottom-start" | "bottom-end""bottom"Horizontal alignment along the bottom edge.
gutterstring"16px"Distance from the bottom edge. Plus env(safe-area-inset-bottom).

ActionBarTrigger

Button that opens the action bar. It does not toggle closed. Renders a button.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child (usually a Button).
classNamestring-Class names on the trigger.
onClickMouseEventHandler-Called after the bar opens.
AttributeDescription
data-slotaction-bar-trigger
data-state"open" or "closed"
aria-expandedtrue when the bar is open

ActionBarContent

Portaled toolbar. Renders a positioner plus a role="toolbar" panel. Give it an accessible name with aria-label or aria-labelledby.

PropTypeDefaultDescription
aria-labelstring-Accessible name for the toolbar.
aria-labelledbystring-Id of a visible label for the toolbar.
asChildbooleanfalseMerge onto a single child of the toolbar panel.
classNamestring-Class names on the toolbar panel (not the positioner).
AttributeDescription
data-slotaction-bar-content on the panel; action-bar-positioner on the fixed wrapper
data-placement"bottom", "bottom-start", or "bottom-end" (positioner)
data-state"open" or "closed" (positioner, from Presence)
roletoolbar
CSS variableDefaultDescription
--space--spacing(2)Internal padding of the toolbar. Set on className, e.g. [--space:--spacing(3)].
--gutterpositioning.gutter (16px)Offset from the bottom edge, including the safe-area inset.

ActionBarValue

Selection count badge. Renders a Badge (variant="secondary"). Display order: children, then label, then count.

PropTypeDefaultDescription
countnumberrequiredNumber of selected items. Also used as the fallback label.
labelstring-Text shown instead of count when children is omitted.
childrenReactNode-Custom content. Overrides label and count.
variantBadge variant"secondary"Badge appearance.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the badge.
AttributeDescription
data-slotaction-bar-value

ActionBarSeparator

Vertical rule between groups. Renders a Separator with orientation="vertical".

PropTypeDefaultDescription
orientation"horizontal" | "vertical""vertical"Forced to vertical by the action bar unless you override it.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the separator.
AttributeDescription
data-slotaction-bar-separator

ActionBarBody

Flex row for primary actions.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the body.
AttributeDescription
data-slotaction-bar-body

ActionBarClose

Button that closes the action bar. Renders a button.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child (usually an icon Button).
aria-labelstring"Close"Accessible name. Override when the child already has visible text.
classNamestring-Class names on the close button.
onClickMouseEventHandler-Called after the bar closes.
AttributeDescription
data-slotaction-bar-close
data-state"open" or "closed"

Accessibility

ActionBarContent is a role="toolbar". Provide an accessible name with aria-label or aria-labelledby. Icon-only close controls should keep an aria-label (the default is "Close").

Keyboard support

KeyDescription
EscapeClose the action bar when closeOnEscape is true (default).
TabMove focus to the next control in the toolbar.
Shift + TabMove focus to the previous control.