fix: preserve nested search names and add browser consumption fixture

This commit is contained in:
maoyingjie
2026-10-25 21:08:28 +08:00
parent 647c39035d
commit b129f79366
7 changed files with 253 additions and 6 deletions
@@ -68,10 +68,19 @@ export default defineComponent({
ctx.filterText.value = text();
}
function compose(nodes: VNodeChild[]): VNodeChild[] {
function compose(
nodes: VNodeChild[],
inheritedAria: readonly string[] = [],
): VNodeChild[] {
return nodes.map((child) => {
if (!isVNode(child)) return child;
const name = componentName(child);
const protectedAria =
name === "SearchField"
? ["aria-label", "aria-labelledby", "aria-describedby"].filter(
(key) => child.props?.[key] !== undefined,
)
: inheritedAria;
if (name === "ListBox") return child;
if (name === "SearchFieldInput") {
const own = (child.props ?? {}) as Record<string, unknown>;
@@ -96,14 +105,18 @@ export default defineComponent({
"aria-labelledby",
"aria-describedby",
]) {
if (own[key] !== undefined) delete injected[key];
if (own[key] !== undefined || protectedAria.includes(key))
delete injected[key];
}
return cloneVNode(child, injected, true);
}
const children = child.children;
if (Array.isArray(children)) {
const clone = cloneVNode(child);
clone.children = compose(children as VNodeChild[]) as never;
clone.children = compose(
children as VNodeChild[],
protectedAria,
) as never;
return clone;
}
if (children && typeof children === "object") {
@@ -116,7 +129,10 @@ export default defineComponent({
clone.children = {
...withDefault,
default: () =>
compose(([withDefault.default!()] as VNodeChild[]).flat()),
compose(
([withDefault.default!()] as VNodeChild[]).flat(),
protectedAria,
),
} as never;
return clone;
}