Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/injected/src/roleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,9 @@ function getTextAlternativeInternal(element: Element, options: AccessibleNameOpt
if (options.outDerivedFromContent && insideTargetElement(options) && trimFlatString(accessibleName.text))
options.outDerivedFromContent.value = true;
// This element owns the accumulated content - record it alongside the descendants it was computed from.
accessibleName.elements?.add(element);
// Whitespace alone is not content, e.g. the spacing around an inline-block icon.
if (trimFlatString(accessibleName.text))
accessibleName.elements?.add(element);
return accessibleName;
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/page/page-aria-snapshot-ai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,22 @@ it('should keep the name when the contributing wrapper collapses into repeating
`);
});

it('should keep the name when an icon wrapper only contributes whitespace to it', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43315' } }, async ({ page }) => {
const icon = `<svg aria-hidden="true" viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6z"></path></svg>`;
const styledIcon = `<svg aria-hidden="true" viewBox="0 0 24 24" style="width: 1em; height: 1em; display: inline-block"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6z"></path></svg>`;
await page.setContent(`
<button><span>\n ${icon}</span>New survey</button>
<button><span>${styledIcon}</span>Edit survey</button>
`);

const snapshot = await snapshotForAI(page);
expect(snapshot).toContainYaml(`
- generic [active] [ref=e1]:
- button "New survey" [ref=e2]
- button "Edit survey" [ref=e6]
`);
});

it('should keep names not derived from printed nodes', async ({ page }) => {
await page.setContent(`
<h3 aria-label="Clipboard API issue"><a style="cursor: pointer" href="/issues/1">Clipboard API</a></h3>
Expand Down