Skip to content

Fix getByTitle for nested SVG title elements#1381

Open
puneetdixit200 wants to merge 1 commit into
testing-library:mainfrom
puneetdixit200:fix-nested-svg-title-query
Open

Fix getByTitle for nested SVG title elements#1381
puneetdixit200 wants to merge 1 commit into
testing-library:mainfrom
puneetdixit200:fix-nested-svg-title-query

Conversation

@puneetdixit200

Copy link
Copy Markdown

What:

Fixes #974 by allowing ByTitle queries to match SVG <title> elements nested under SVG graphics elements.

Why:

getByTitle('Close') currently only finds direct svg > title elements, so an SVG like <path><title>Close</title></path> cannot be queried by title even though the title labels the graphics element.

How:

The title query now scans SVG title descendants and resolves a matched nested SVG title to the element it labels. The existing direct svg > title behavior is preserved. A regression test covers the nested <path><title>...</title></path> case.

Checklist:

  • Documentation added to the docs site: N/A, bug fix covered by tests
  • Tests
  • TypeScript definitions updated: N/A, no type changes
  • Ready to be merged

@codesandbox-ci

codesandbox-ci Bot commented Jun 4, 2026

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9d326ca:

Sandbox Source
react-testing-library-examples Configuration

@puneetdixit200 puneetdixit200 force-pushed the fix-nested-svg-title-query branch from cd983ea to 9d326ca Compare June 4, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getByTitle for SVGs canot find title if it's not a direct child of svg

1 participant