fix: retain fallback ColorSwatch ids on slot roots
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
Comment,
|
||||
Fragment,
|
||||
Text,
|
||||
cloneVNode,
|
||||
computed,
|
||||
getCurrentInstance,
|
||||
h,
|
||||
@@ -160,13 +161,6 @@ function roleDescription() {
|
||||
: "color swatch";
|
||||
}
|
||||
|
||||
/** Reka Slot keeps a child's own ID over merged attrs; mirror that root ID. */
|
||||
function asChildRootId(children: VNodeChild) {
|
||||
const root = meaningfulVNodes(children)[0];
|
||||
const id = root?.props?.id;
|
||||
return id == null ? undefined : String(id);
|
||||
}
|
||||
|
||||
function setRoot(node: unknown) {
|
||||
const next =
|
||||
node instanceof HTMLElement
|
||||
@@ -177,11 +171,18 @@ function setRoot(node: unknown) {
|
||||
|
||||
/** Functional render layer so the default slot is read once per render. */
|
||||
const Render = () => {
|
||||
const children = slots.default?.({ color: displayColor.value }) as
|
||||
let children = slots.default?.({ color: displayColor.value }) as
|
||||
VNodeChild | undefined;
|
||||
const childId = props.asChild ? asChildRootId(children) : undefined;
|
||||
const childNodes = props.asChild ? meaningfulVNodes(children) : undefined;
|
||||
const childId = childNodes?.[0]?.props?.id;
|
||||
const effectiveId =
|
||||
childId ?? (attrs.id == null ? generatedId : String(attrs.id));
|
||||
// Slot gives child props precedence, including an explicit undefined ID.
|
||||
// Put the resolved ID on that VNode too, preserving Vue's ref and key.
|
||||
if (childNodes?.length) {
|
||||
childNodes[0] = cloneVNode(childNodes[0]!, { id: effectiveId });
|
||||
children = childNodes;
|
||||
}
|
||||
const labelledBy = attrs["aria-labelledby"];
|
||||
|
||||
return h(
|
||||
|
||||
Reference in New Issue
Block a user