nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[Bug] ButtonGroup/ToggleButtonGroup Separator renders as a stray vertical line (absolute positioning, no anchor)

Open Fldicoahkiin opened this issue 5 months ago • 1 comments

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) is inline-flex … gap-0 with no position: 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-group is inline-flex … gap-0 (no position: relative); .button-group__separator is position: absolute; left: -1px.
  • packages/styles/components/toggle-button-group.css — same shape.
  • packages/react/src/components/button-group/button-group.tsx (and toggle-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 a position: relative wrapper). Then left: -1px lands 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/react 3.2.1, @heroui/styles 3.2.1
  • v3 branch HEAD is byte-identical to the published 3.2.1 CSS.

Fldicoahkiin avatar Jun 29 '26 17:06 Fldicoahkiin

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.

Fldicoahkiin avatar Jul 02 '26 13:07 Fldicoahkiin