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:
@@ -410,7 +410,7 @@ Dropdown 组件实现 ARIA 菜单模式,并提供:
|
|||||||
- 官方 `items` + 渲染函数的数据驱动集合用 `v-for` 表达;`renderEmptyState` 对应 `empty` 插槽。不提供 React Collection 对象模型。
|
- 官方 `items` + 渲染函数的数据驱动集合用 `v-for` 表达;`renderEmptyState` 对应 `empty` 插槽。不提供 React Collection 对象模型。
|
||||||
- 子菜单悬停展开延迟由底层固定为 100ms,未暴露官方 `delay`(默认 200ms);子菜单面板的 `side`/`align` 由底层固定,只有偏移与碰撞参数可调。
|
- 子菜单悬停展开延迟由底层固定为 100ms,未暴露官方 `delay`(默认 200ms);子菜单面板的 `side`/`align` 由底层固定,只有偏移与碰撞参数可调。
|
||||||
- `DropdownTrigger` 的作用域插槽只提供 `{ isOpen }`,`DropdownPopover` 只提供 `{ isEntering, isExiting, placement }`;官方 Button/Popover 的完整 render props 未全部覆盖。
|
- `DropdownTrigger` 的作用域插槽只提供 `{ isOpen }`,`DropdownPopover` 只提供 `{ isEntering, isExiting, placement }`;官方 Button/Popover 的完整 render props 未全部覆盖。
|
||||||
- `DropdownRoot` 额外渲染一层 `.hv-dropdown` 包裹元素(官方该类没有 DOM 宿主),用于承载根级 class 与方向。
|
- `DropdownRoot` 额外渲染一层 `.hv-dropdown` 包裹元素(官方该类没有 DOM 宿主),用于承载根级 class 与方向。作为 `ButtonGroup` 直接子级时省略该包裹元素,让触发按钮保持组内的位置接缝;该场景下根级 attrs 与官方一致不落 DOM。
|
||||||
- 条目 `id` 是业务 key,DOM id 为实例级;官方把 key 直接作为 DOM id(Vue 端避免数字 `0` 与字符串 `"0"` 冲突)。
|
- 条目 `id` 是业务 key,DOM id 为实例级;官方把 key 直接作为 DOM id(Vue 端避免数字 `0` 与字符串 `"0"` 冲突)。
|
||||||
- 条目 `onClick` 中 `preventDefault()` 会取消动作、选择与关闭;`stopImmediatePropagation()` 会终止后续处理器,均为原生事件语义。
|
- 条目 `onClick` 中 `preventDefault()` 会取消动作、选择与关闭;`stopImmediatePropagation()` 会终止后续处理器,均为原生事件语义。
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
/** Long-press duration in ms (longPress trigger). */
|
/** Long-press duration in ms (longPress trigger). */
|
||||||
longPressDuration: { type: Number, default: LONG_PRESS_DURATION },
|
longPressDuration: { type: Number, default: LONG_PRESS_DURATION },
|
||||||
|
/**
|
||||||
|
* Absorbs ButtonGroup's direct-child marker; not a public API. When marked,
|
||||||
|
* the root wrapper is skipped so the trigger keeps the positional slot the
|
||||||
|
* group seam styles rely on — upstream `Dropdown` has no DOM root (RAC
|
||||||
|
* `MenuTrigger` renders a bare SlotProvider) and drops root-level attrs.
|
||||||
|
*/
|
||||||
|
__button_group_child: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
emits: ["update:open"],
|
emits: ["update:open"],
|
||||||
setup(props, { slots, emit }) {
|
setup(props, { slots, emit }) {
|
||||||
@@ -59,8 +66,23 @@ export default defineComponent({
|
|||||||
suppressOpenRequests,
|
suppressOpenRequests,
|
||||||
});
|
});
|
||||||
|
|
||||||
return () =>
|
return () => {
|
||||||
h(
|
const menu = h(
|
||||||
|
RekaDropdownMenuRoot as never,
|
||||||
|
{
|
||||||
|
open: isOpen.value,
|
||||||
|
defaultOpen: props.defaultOpen,
|
||||||
|
dir: props.dir,
|
||||||
|
modal: props.modal,
|
||||||
|
"onUpdate:open": (value: boolean) => setOpen(value),
|
||||||
|
},
|
||||||
|
{ default: () => slots.default?.() },
|
||||||
|
);
|
||||||
|
// ButtonGroup member: no wrapper element, so the trigger button is the
|
||||||
|
// group's positional child and the shared seam rules apply unchanged.
|
||||||
|
if (props.__button_group_child) return menu;
|
||||||
|
|
||||||
|
return h(
|
||||||
"div",
|
"div",
|
||||||
{
|
{
|
||||||
...attrs,
|
...attrs,
|
||||||
@@ -68,20 +90,9 @@ export default defineComponent({
|
|||||||
"data-slot": "dropdown-root",
|
"data-slot": "dropdown-root",
|
||||||
"data-trigger": props.trigger,
|
"data-trigger": props.trigger,
|
||||||
},
|
},
|
||||||
[
|
[menu],
|
||||||
h(
|
|
||||||
RekaDropdownMenuRoot as never,
|
|
||||||
{
|
|
||||||
open: isOpen.value,
|
|
||||||
defaultOpen: props.defaultOpen,
|
|
||||||
dir: props.dir,
|
|
||||||
modal: props.modal,
|
|
||||||
"onUpdate:open": (value: boolean) => setOpen(value),
|
|
||||||
},
|
|
||||||
{ default: () => slots.default?.() },
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
ButtonGroup,
|
ButtonGroup,
|
||||||
ButtonGroupSeparator,
|
ButtonGroupSeparator,
|
||||||
|
DropdownRoot,
|
||||||
|
DropdownTrigger,
|
||||||
ToggleButton,
|
ToggleButton,
|
||||||
ToggleButtonGroup,
|
ToggleButtonGroup,
|
||||||
ToggleButtonGroupSeparator,
|
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", () => {
|
describe("M26 review regressions beyond the probe file", () => {
|
||||||
it("RTL horizontal groups reverse arrow direction across three members", async () => {
|
it("RTL horizontal groups reverse arrow direction across three members", async () => {
|
||||||
const w = mount(
|
const w = mount(
|
||||||
|
|||||||
Reference in New Issue
Block a user