fix(dropdown): preserve grouped root attrs and events without breaking seams

This commit is contained in:
maoyingjie
2026-10-28 12:35:35 +08:00
parent 8b1505438e
commit f8de4529f6
12 changed files with 305 additions and 23 deletions
@@ -146,3 +146,73 @@
.hv-button-group--full-width {
@apply w-full;
}
/* Vue Dropdown keeps a root element for consumer attrs and capture events.
* Its trigger's position belongs to that wrapper, not to the trigger's own
* :first-child/:last-child. Scope the correction to marked direct members;
* ordinary buttons and standalone dropdowns retain the baseline rules. */
.hv-button-group > .hv-dropdown[data-button-group-child] > .hv-button {
@apply rounded-none;
}
.hv-button-group--horizontal
> .hv-dropdown[data-button-group-child]:first-child
> .hv-button {
@apply rounded-s-3xl;
}
.hv-button-group--horizontal
> .hv-dropdown[data-button-group-child]:last-child
> .hv-button {
@apply rounded-e-3xl;
}
.hv-button-group--vertical
> .hv-dropdown[data-button-group-child]:first-child
> .hv-button {
@apply rounded-t-3xl;
}
.hv-button-group--vertical
> .hv-dropdown[data-button-group-child]:last-child
> .hv-button {
@apply rounded-b-3xl;
}
/* Only the outer outline edges remain; utilities on the trigger may still
* override these component-layer defaults, as they do for direct Buttons. */
.hv-button-group--horizontal
> .hv-dropdown[data-button-group-child]
> .hv-button--outline {
@apply border-x-0;
}
.hv-button-group--horizontal
> .hv-dropdown[data-button-group-child]:first-child
> .hv-button--outline {
@apply border-s;
}
.hv-button-group--horizontal
> .hv-dropdown[data-button-group-child]:last-child
> .hv-button--outline {
@apply border-e;
}
.hv-button-group--vertical
> .hv-dropdown[data-button-group-child]
> .hv-button--outline {
@apply border-y-0;
}
.hv-button-group--vertical
> .hv-dropdown[data-button-group-child]:first-child
> .hv-button--outline {
@apply border-t;
}
.hv-button-group--vertical
> .hv-dropdown[data-button-group-child]:last-child
> .hv-button--outline {
@apply border-b;
}
@@ -33,10 +33,9 @@ export default defineComponent({
/** Long-press duration in ms (longPress trigger). */
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.
* Absorbs ButtonGroup's direct-child marker; not a public API. The wrapper
* remains the attrs/event host; group styles use its position to shape the
* nested trigger instead of dropping the root and its consumer attributes.
*/
__button_group_child: { type: Boolean, default: false },
},
@@ -78,10 +77,6 @@ export default defineComponent({
},
{ 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",
{
@@ -89,6 +84,7 @@ export default defineComponent({
class: [slotsComputed.value.root(), attrs.class],
"data-slot": "dropdown-root",
"data-trigger": props.trigger,
"data-button-group-child": props.__button_group_child || undefined,
},
[menu],
);