Button Group
Buttons join into one strip, and a single highlight glides from segment to segment under the pointer or keyboard focus, taking each segment's corners as it goes.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/button-groupThis adds components/keyframery/button-group.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Button } from "@/components/keyframery/button"
import { ButtonGroup } from "@/components/keyframery/button-group"
export default function Usage() {
return (
<ButtonGroup aria-label="Text alignment">
<Button>Left</Button>
<Button>Center</Button>
<Button>Right</Button>
</ButtonGroup>
)
}Examples
Basic
Buttons inside join into one strip, and one highlight glides between them under the pointer or keyboard focus.
Split button
A main action and a menu of the others share one key. ButtonGroupSeparator draws the line between them.
Vertical and nested
orientation="vertical" stacks the buttons. Groups inside a group keep a gap between them.
Motion
| Move | What you see |
|---|---|
| Glide | One highlight springs from segment to segment instead of each button lighting up on its own. |
| Fade | The highlight appears where it lands the first time and fades out where it was when the pointer leaves. |
| Press | A segment sinks a little and springs back, less than a lone button so the strip stays joined. |
| Draw | A separator grows in from its centre. |
Timing and springiness follow the motion style you set. To change how fast this button group moves, pass speed:
<ButtonGroup speed="fast">
…
</ButtonGroup>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--button-group-face | Counter surface | bg-muted |
--button-group-ink | Counter text | text-muted-foreground |
--button-group-line | Separator | bg-border |
--button-group-radius | Counter corners | rounded-[9px] |
--button-group-font | Counter size | text-[13px] |
--button-group-gap | Nested group gap | 0.5rem |
--button-group-inset-x | Counter padding | px-3 |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
ButtonGroup
Renders a <div>, and takes its props too.
Prop
Type
ButtonGroupSeparator
Renders a <div>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
ButtonGroupText: a<div>
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to the next control in the group; each one is its own tab stop. |
| Shift + Tab | Moves to the previous control. |
| Enter | Presses the focused button. |
| Space | Presses the focused button. |
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a button group, so this one is defined with its core: one definePrimitive in components/keyframery/core/button-group-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/button-group.
Questions
How does the animated Button Group for UI SDK move?
Glide: One highlight springs from segment to segment instead of each button lighting up on its own. Fade: The highlight appears where it lands the first time and fades out where it was when the pointer leaves. Press: A segment sinks a little and springs back, less than a lone button so the strip stays joined. Draw: A separator grows in from its centre.
Do I need Motion or Framer Motion for the animated Button Group?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no button group. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/button-group-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Button Group when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.