fix(dropdown): keep dropdown trigger positional inside ButtonGroup

Review of the restored button-group demos found the merged pull-request
group's seam broken: DropdownRoot renders a .hv-dropdown wrapper (a recorded
Vue adaptation) so the trigger button stopped being a positional child of
.button-group and matched :first-child:last-child, taking a full 24px radius
against the merge button's 24/0 end cap. The internal __button_group_child
marker also leaked onto the DOM.

Upstream Dropdown has no DOM root (RAC MenuTrigger renders a bare
SlotProvider and drops root props), so the trigger naturally occupies the
group's :last-child slot and the shared seam rules apply unchanged.

- DropdownRoot absorbs the ButtonGroup direct-child marker and skips the
  wrapper when marked, restoring positional seam radii and outline seam
  borders without touching the styles package (kept line-parity with the
  pinned source)
- wrapper contract (data-slot=dropdown-root, data-trigger, root class host)
  unchanged outside ButtonGroup; documented in dropdown.md
- regression tests: positional trigger + no marker leak in groups, wrapper
  still hosts root class standalone
This commit is contained in:
maoyingjie
2026-10-28 11:39:39 +08:00
parent dfd5248c9b
commit 123e3f9cba
3 changed files with 74 additions and 16 deletions
+47
View File
@@ -6,6 +6,8 @@ import {
Button,
ButtonGroup,
ButtonGroupSeparator,
DropdownRoot,
DropdownTrigger,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
@@ -603,6 +605,51 @@ describe("ButtonGroup fullWidth inheritance", () => {
});
});
describe("ButtonGroup dropdown composition", () => {
it("keeps the dropdown trigger positional for the shared seam styles", () => {
const w = mount(
defineComponent({
render: () =>
h(ButtonGroup, () => [
h(Button, () => "合并拉取请求"),
h(DropdownRoot, () => [
h(DropdownTrigger, null, () =>
h(
Button,
{ isIconOnly: true, "aria-label": "更多选项" },
() => "更多选项",
),
),
]),
]),
}),
);
const group = w.get('[data-slot="button-group"]');
const trigger = w.get('button[aria-label="更多选项"]');
// The group seam CSS keys off positional children and upstream Dropdown
// has no DOM root: the trigger must sit directly in the group, with no
// wrapper in between and no internal marker leaked onto the DOM.
expect(trigger.element.parentElement).toBe(group.element);
expect(trigger.element.matches(":last-child")).toBe(true);
expect(w.html()).not.toContain("__button_group_child");
expect(w.find('[data-slot="dropdown-root"]').exists()).toBe(false);
w.unmount();
});
it("still hosts root attrs on the wrapper outside ButtonGroup", () => {
const w = mount(DropdownRoot, {
attrs: { class: "custom-root" },
slots: {
default: () => h(DropdownTrigger, null, () => h(Button, () => "操作")),
},
});
const root = w.get('[data-slot="dropdown-root"]');
expect(root.classes()).toContain("custom-root");
expect(root.attributes("data-trigger")).toBe("press");
w.unmount();
});
});
describe("M26 review regressions beyond the probe file", () => {
it("RTL horizontal groups reverse arrow direction across three members", async () => {
const w = mount(