Skip to content

Commit cf777ae

Browse files
committed
generate correct IDs for shadow DOM elements
1 parent f45afdc commit cf777ae

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/a11y/utils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ export async function buildBackendIdMaps(
195195
const stack: StackEntry[] = [{ node: startNode, path: "", fid: rootFid }];
196196
const seen = new Set<EncodedId>();
197197

198+
const joinStep = (base: string, step: string): string =>
199+
base.endsWith("//") ? `${base}${step}` : `${base}/${step}`;
200+
198201
while (stack.length) {
199202
const { node, path, fid } = stack.pop()!;
200203

@@ -212,6 +215,16 @@ export async function buildBackendIdMaps(
212215
stack.push({ node: node.contentDocument, path: "", fid: childFid });
213216
}
214217

218+
if (node.shadowRoots?.length) {
219+
for (const shadowRoot of node.shadowRoots) {
220+
stack.push({
221+
node: shadowRoot,
222+
path: `${path}//`,
223+
fid,
224+
});
225+
}
226+
}
227+
215228
// push children
216229
const kids = node.children ?? [];
217230
if (kids.length) {
@@ -234,7 +247,7 @@ export async function buildBackendIdMaps(
234247
for (let i = kids.length - 1; i >= 0; i--) {
235248
stack.push({
236249
node: kids[i]!,
237-
path: `${path}/${segs[i]}`,
250+
path: joinStep(path, segs[i]!),
238251
fid,
239252
});
240253
}

0 commit comments

Comments
 (0)