How to use
ButtonGroup merges a row of adjacent Buttons into a single visually connected control — shared borders where they touch, radius only on the outer corners, and one set of default props (variant, color, size, radius, fullWidth, isDisabled) that every child inherits unless it sets its own. It's a styling/defaults wrapper, not a selection manager — it doesn't track which child is "active" for you.
import { Button, ButtonGroup } from "oks-ui";Set variant/color/size/radius once on ButtonGroup instead of repeating them on every Button — any child Button that doesn't set its own value for a given prop inherits the group's, and one that does set its own overrides just that prop while still inheriting the rest.
<ButtonGroup variant="bordered" color="default">
<Button>Day</Button>
<Button>Week</Button>
<Button color="primary">Month</Button>
</ButtonGroup>The inheritance walks React.Children directly — a Button wrapped in another element (a styled <div>, a conditional fragment) won't pick up the group's defaults, since ButtonGroup has no reliable way to know what counts as a "wrapper" versus an unrelated child. Keep Buttons as direct children of ButtonGroup, even if you need conditional rendering around them.
// Works -- both are direct children
<ButtonGroup variant="soft">
<Button>A</Button>
{showB && <Button>B</Button>}
</ButtonGroup>
// Doesn't inherit -- Button is nested inside a wrapper, not a direct child
<ButtonGroup variant="soft">
<div className="wrapper"><Button>A</Button></div>
</ButtonGroup>ButtonGroup itself has no concept of a selected item — for a segmented control where exactly one option is active, track the selection in your own state and drive each Button's color/variant off it.
function ViewToggle() {
const [view, setView] = useState<"list" | "grid">("list");
return (
<ButtonGroup variant="bordered" size="sm">
<Button
color={view === "list" ? "primary" : "default"}
onPress={() => setView("list")}
>
List
</Button>
<Button
color={view === "grid" ? "primary" : "default"}
onPress={() => setView("grid")}
>
Grid
</Button>
</ButtonGroup>
);
}Unlike Button, ButtonGroup's colorDepth prop has no built-in default value — it stays unset (letting each child Button fall back to its own default) until you explicitly provide one, at which point it applies to every child that doesn't set colorDepth itself.
All available props for ButtonGroup. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Buttons rendered inside the group. |
children
ReactNode
Default: —
Buttons rendered inside the group.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "solid" | "soft" | "bordered" | "ghost" | "link" | solid | Default variant for child Buttons that don't set their own. |
color | "default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger" | default | Default color for child Buttons that don't set their own. |
colorDepth | 50 | 100 | ... | 950 | — | Optional default depth, only applied when provided. |
size | "xs" | "xs-sm" | "sm" | "md" | "lg" | "xl" | md | Default size for child Buttons that don't set their own. |
radius | "none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full" | md | Default radius for child Buttons that don't set their own. |
variant
"solid" | "soft" | "bordered" | "ghost" | "link"
Default: solid
Default variant for child Buttons that don't set their own.
color
"default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger"
Default: default
Default color for child Buttons that don't set their own.
colorDepth
50 | 100 | ... | 950
Default: —
Optional default depth, only applied when provided.
size
"xs" | "xs-sm" | "sm" | "md" | "lg" | "xl"
Default: md
Default size for child Buttons that don't set their own.
radius
"none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full"
Default: md
Default radius for child Buttons that don't set their own.
| Prop | Type | Default | Description |
|---|---|---|---|
fullWidth | boolean | false | Default fullWidth for child Buttons that don't set their own. |
fullWidth
boolean
Default: false
Default fullWidth for child Buttons that don't set their own.
| Prop | Type | Default | Description |
|---|---|---|---|
isDisabled | boolean | false | Disables all child Buttons that don't set isDisabled explicitly. |
role | string | group | ARIA role for the group container. |
isDisabled
boolean
Default: false
Disables all child Buttons that don't set isDisabled explicitly.
role
string
Default: group
ARIA role for the group container.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Class applied to the root element. |
style | CSSProperties | — | Inline styles for the root element. |
className
string
Default: —
Class applied to the root element.
style
CSSProperties
Default: —
Inline styles for the root element.