[Bug] ButtonGroup/ToggleButtonGroup Separator renders as a stray vertical line (absolute positioning, no anchor)
Describe the bug
<ButtonGroup.Separator> and <ToggleButtonGroup.Separator> do not render a divider between the buttons. Instead they collapse into a single stray ~1px vertical line on the left edge of the nearest positioned ancestor (e.g. a position: relative Card wrapping the group).
Root cause
The separator renders as a <span data-slot="button-group-separator"> that is a sibling of the buttons inside the group, styled (horizontal orientation):
.button-group__separator {
position: absolute;
left: -1px;
top: 25%;
width: 1px;
height: 50%;
}
position: absolute; left: -1px only lands on the segment boundary if the separator's offset parent is the adjacent button (or a per-segment position: relative wrapper). Neither exists:
- The group base (
.button-group/.toggle-button-group) isinline-flex … gap-0with noposition: relative, so it is not a positioning context. - The buttons are
position: relative, but the separator is their sibling, not a descendant, so the buttons' positioning context does not apply to it.
With no anchor, each separator's offset parent bubbles up to the nearest positioned ancestor. When the group sits inside a position: relative container (a Card, a panel, …), every separator collapses onto that container's left edge at left: -1px, stacking into one stray vertical line.
Reproduction
<div style={{ position: "relative" }}>
<ToggleButtonGroup defaultSelectedKeys={["light"]}>
<ToggleButton id="light">Light</ToggleButton>
<ToggleButtonGroup.Separator />
<ToggleButton id="dark">Dark</ToggleButton>
<ToggleButtonGroup.Separator />
<ToggleButton id="system">System</ToggleButton>
</ToggleButtonGroup>
</div>
Expected: thin dividers between the buttons.
Actual: no dividers between buttons; a single ~1px vertical line at the left edge of the position: relative wrapper.
Affected source (v3 branch HEAD, identical to published @heroui/styles 3.2.1)
packages/styles/components/button-group.css—.button-groupisinline-flex … gap-0(noposition: relative);.button-group__separatorisposition: absolute; left: -1px.packages/styles/components/toggle-button-group.css— same shape.packages/react/src/components/button-group/button-group.tsx(andtoggle-button-group.tsx) — Root renders children directly; the separator is a standalone<span>with no per-button wrapper.
Suggested fix
The absolute separator needs a per-segment positioning anchor:
- A. Anchor the separator to its adjacent button (render it inside the button — which is already
position: relative— or wrap each segment in aposition: relativewrapper). Thenleft: -1pxlands on the boundary. - B. Drop absolute positioning and draw the divider in-flow (a border /
divide-*between adjacent buttons), removing the offset-parent dependency entirely.
Note: adding position: relative to the group alone does not fix it — all separators then stack on the group's own left edge.
Version
@heroui/react3.2.1,@heroui/styles3.2.1- v3 branch HEAD is byte-identical to the published 3.2.1 CSS.
Closing — this was a misuse on my side, not a bug: the documented placement puts the separator inside the following button (which anchors the absolute positioning correctly). Details in #6681.