Expandable Action Bar

A compact pill-shaped action bar that shows icon-only buttons and expands them into labeled controls on hover, focus, or tap, with shared layout animation between items. It supports active state, badges, shortcuts, and controlled or uncontrolled expansion.

Expandable Action Bar
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme from registry.json
See how it was built

Installation

pnpm dlx shadcn@latest add @beui/expandable-action-bar

Requires @beui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { ExpandableActionBar, type ExpandableActionBarItem } from "@/components/motion/expandable-action-bar";import { Home, Search, Settings } from "lucide-react";const items: ExpandableActionBarItem[] = [  { id: "home", label: "Home", icon: <Home /> },  { id: "search", label: "Search", icon: <Search />, shortcut: "/" },  { id: "settings", label: "Settings", icon: <Settings /> },];export function Example() {  return <ExpandableActionBar items={items} activeId="home" onAction={(item) => console.log(item.id)} />;}
  • Use a floating or docked toolbar where space is tight but important actions need readable labels on demand.
  • Use for contextual action sets such as editor tools, media player controls, or a per-page quick action dock.
  • Use when you want hover or focus reveal on desktop and a two-tap reveal-then-act pattern on touch devices.
  • Avoid when every action must always show its label, or when the bar must be the sole route to critical actions on touch-only surfaces.

Examples

Basic toolbar with labels and shortcuts

Uncontrolled bar with an active item, a badge, and a keyboard shortcut hint. Clicking an item calls onAction.

basic-toolbar-with-labels-and-shortcuts.tsx
import { ExpandableActionBar, type ExpandableActionBarItem } from "@/components/motion/expandable-action-bar";import { Bell, Pencil, Search } from "lucide-react";const items: ExpandableActionBarItem[] = [  { id: "edit", label: "Edit", icon: <Pencil />, shortcut: "E" },  { id: "search", label: "Search", icon: <Search />, shortcut: "/" },  { id: "alerts", label: "Alerts", icon: <Bell />, badge: 3 },];export function ToolbarExample() {  return (    <ExpandableActionBar      items={items}      activeId="edit"      onAction={(item) => console.log("run", item.id)}    />  );}

Controlled expansion with the state hook

useExpandableActionBar supplies expanded state and the active id. Wire it into the component's controlled props.

controlled-expansion-with-the-state-hook.tsx
import { ExpandableActionBar, type ExpandableActionBarItem, useExpandableActionBar } from "@/components/motion/expandable-action-bar";import { Crop, Type, Image } from "lucide-react";const items: ExpandableActionBarItem[] = [  { id: "crop", label: "Crop", icon: <Crop /> },  { id: "text", label: "Text", icon: <Type /> },  { id: "image", label: "Image", icon: <Image /> },];export function ControlledExample() {  const bar = useExpandableActionBar(items);  return (    <ExpandableActionBar      items={items}      expanded={bar.expanded}      onExpandedChange={bar.setExpanded}      activeId={bar.activeId}      onAction={(item) => bar.setActiveId(item.id)}    />  );}

Custom item rendering and class overrides

renderItem replaces the default icon, label, and badge layout. classNames restyles the root, track, and active item.

custom-item-rendering-and-class-overrides.tsx
import { ExpandableActionBar, type ExpandableActionBarItem } from "@/components/motion/expandable-action-bar";import { Heart, Share2 } from "lucide-react";const items: ExpandableActionBarItem[] = [  { id: "like", label: "Like", icon: <Heart /> },  { id: "share", label: "Share", icon: <Share2 /> },];export function CustomExample() {  return (    <ExpandableActionBar      size="sm"      items={items}      classNames={{ track: "border-primary/40", activeItem: "text-primary" }}      renderItem={(item, { expanded }) => (        <span className="inline-flex items-center gap-1">          {item.icon}          {expanded ? <span>{String(item.label)}</span> : null}        </span>      )}    />  );}

Touch-first bar that acts on every tap

Disables hover and focus expansion so each tap runs the action immediately.

touch-first-bar-that-acts-on-every-tap.tsx
import { ExpandableActionBar, type ExpandableActionBarItem } from "@/components/motion/expandable-action-bar";import { Play, Pause, SkipForward } from "lucide-react";const items: ExpandableActionBarItem[] = [  { id: "play", label: "Play", icon: <Play /> },  { id: "pause", label: "Pause", icon: <Pause /> },  { id: "next", label: "Next", icon: <SkipForward /> },];export function TouchExample() {  return (    <ExpandableActionBar      items={items}      expandOnHover={false}      expandOnFocus={false}      onAction={(item) => console.log(item.id)}    />  );}

API reference

PropTypeDefaultDescription
itemsExpandableActionBarItem[]—Actions to render. Each item has id, label, icon, and optional onClick, disabled, active, badge, and shortcut. The label is also used as the title tooltip when it is a string.
expandedboolean—Controlled expansion state. When provided, the bar ignores its internal state and reports changes through onExpandedChange.
defaultExpandedbooleanfalseInitial expansion state when uncontrolled.
onExpandedChange(expanded: boolean) => void—Called whenever the bar wants to expand or collapse, in both controlled and uncontrolled modes.
activeIdstring—Id of the active item. Overrides any item with active set to true. The active item is highlighted when nothing is hovered.
onAction(item: ExpandableActionBarItem) => void—Called with the item after its onClick runs. On touch with expandOnHover enabled, the first tap only expands and does not call this.
size"sm" | "md""md"Visual density of the track, items, and icons.
expandOnHoverbooleantrueExpand when a hovering pointer rests on the bar. Also governs touch: the first tap expands the bar without running an action, and the second tap acts. Set false so every tap and click acts immediately.
expandOnFocusbooleantrueExpand when focus enters the bar and collapse when focus leaves it entirely.
collapseDelaynumber90Milliseconds to wait before collapsing after the pointer leaves or focus exits. Lets the pointer cross small gaps without flicker.
classNamestring—Class names applied to the outer motion wrapper, merged with classNames.root via cn.
classNamesExpandableActionBarClassNames—Slot overrides for root, track, item, activeItem, icon, label, badge, and shortcut. Each is merged with its default classes.
renderItem(item: ExpandableActionBarItem, state: { expanded: boolean; active: boolean }) => ReactNode—Replaces the default content inside each button. The button, layout, and highlight remain managed by the component.

Accessibility

  • Each action is a native button with type="button", so it is keyboard focusable and activates with Enter and Space.
  • Focus entering the bar expands it, so keyboard users can read the labels as they tab through items.
  • The label span is aria-hidden while collapsed, so screen readers do not read hidden text twice. The accessible name still comes from the title attribute when the label is a string.
  • Icons are rendered as-is; pass aria-label on the item's icon or use renderItem if an icon-only control needs a clearer name.
  • Disabled items use the disabled attribute and pointer-events-none, so they are skipped by pointer and keyboard.
  • The bar respects prefers-reduced-motion: width, blur, and slide animations are replaced with instant changes and whileTap scaling is removed.
  • Pressing a key on an item drops any pending touch gesture state, so keyboard activation is never confused with a tap.
  • Escape on a touch-expanded bar collapses it through the dismiss hook.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Expandable Action Bar" component (beui/expandable-action-bar) from its shadcn registry.1. Install it with: npx shadcn@latest add @beui/expandable-action-bar2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: items, expanded, defaultExpanded, onExpandedChange, activeId, onAction, size, expandOnHover, expandOnFocus, collapseDelay, className, classNames, renderItem.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ExpandableActionBar, type ExpandableActionBarItem } from "@/components/motion/expandable-action-bar";import { Home, Search, Settings } from "lucide-react";const items: ExpandableActionBarItem[] = [  { id: "home", label: "Home", icon: <Home /> },  { id: "search", label: "Search", icon: <Search />, shortcut: "/" },  { id: "settings", label: "Settings", icon: <Settings /> },];export function Example() {  return <ExpandableActionBar items={items} activeId="home" onAction={(item) => console.log(item.id)} />;}```

Files & dependencies

  • components/motion/expandable-action-bar.tsx→ @components/motion/expandable-action-bar.tsx
  • lib/ease.ts→ @lib/ease.ts
  • lib/hooks/use-dismiss.ts→ @lib/hooks/use-dismiss.ts
  • lib/hooks/use-hover-gesture.ts→ @lib/hooks/use-hover-gesture.ts
  • lib/hooks/use-tap-gesture.ts→ @lib/hooks/use-tap-gesture.ts
  • lib/utils.ts→ @lib/utils.ts
  • lib/layers.ts→ @lib/layers.ts
  • lib/touch.ts→ @lib/touch.ts
dependenciesclsxmotiontailwind-merge
registryDependencieshttps://beui.dev/r/theme.json

Looks similar, elsewhere