Skip to content

Commit a204ca1

Browse files
committed
generate correct IDs for shadow DOM elements
1 parent 0c7c39b commit a204ca1

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
@@ -194,6 +194,9 @@ export async function buildBackendIdMaps(
194194
const stack: StackEntry[] = [{ node: startNode, path: "", fid: rootFid }];
195195
const seen = new Set<EncodedId>();
196196

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

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

217+
if (node.shadowRoots?.length) {
218+
for (const shadowRoot of node.shadowRoots) {
219+
stack.push({
220+
node: shadowRoot,
221+
path: `${path}//`,
222+
fid,
223+
});
224+
}
225+
}
226+
214227
// push children
215228
const kids = node.children ?? [];
216229
if (kids.length) {
@@ -233,7 +246,7 @@ export async function buildBackendIdMaps(
233246
for (let i = kids.length - 1; i >= 0; i--) {
234247
stack.push({
235248
node: kids[i]!,
236-
path: `${path}/${segs[i]}`,
249+
path: joinStep(path, segs[i]!),
237250
fid,
238251
});
239252
}

0 commit comments

Comments
 (0)