@@ -14,9 +14,21 @@ import {
1414 buildQueries ,
1515} from './all-utils'
1616
17- const isSvgTitle = ( node : HTMLElement ) =>
18- node . tagName . toLowerCase ( ) === 'title' &&
19- node . parentElement ?. tagName . toLowerCase ( ) === 'svg'
17+ const getSvgTitleOwner = ( node : HTMLElement ) => {
18+ if (
19+ node . tagName . toLowerCase ( ) !== 'title' ||
20+ node . namespaceURI !== 'http://www.w3.org/2000/svg'
21+ ) {
22+ return null
23+ }
24+
25+ const parent = node . parentElement
26+ if ( ! parent || parent . tagName . toLowerCase ( ) === 'svg' ) {
27+ return node
28+ }
29+
30+ return parent
31+ }
2032
2133const queryAllByTitle : AllByBoundAttribute = (
2234 container ,
@@ -26,14 +38,25 @@ const queryAllByTitle: AllByBoundAttribute = (
2638 checkContainerType ( container )
2739 const matcher = exact ? matches : fuzzyMatches
2840 const matchNormalizer = makeNormalizer ( { collapseWhitespace, trim, normalizer} )
29- return Array . from (
30- container . querySelectorAll < HTMLElement > ( '[title], svg > title' ) ,
31- ) . filter (
32- node =>
33- matcher ( node . getAttribute ( 'title' ) , node , text , matchNormalizer ) ||
34- ( isSvgTitle ( node ) &&
35- matcher ( getNodeText ( node ) , node , text , matchNormalizer ) ) ,
36- )
41+ const results = new Set < HTMLElement > ( )
42+
43+ Array . from (
44+ container . querySelectorAll < HTMLElement > ( '[title], svg title' ) ,
45+ ) . forEach ( node => {
46+ if ( matcher ( node . getAttribute ( 'title' ) , node , text , matchNormalizer ) ) {
47+ results . add ( node )
48+ }
49+
50+ const svgTitleOwner = getSvgTitleOwner ( node )
51+ if (
52+ svgTitleOwner &&
53+ matcher ( getNodeText ( node ) , svgTitleOwner , text , matchNormalizer )
54+ ) {
55+ results . add ( svgTitleOwner )
56+ }
57+ } )
58+
59+ return Array . from ( results )
3760}
3861
3962const getMultipleError : GetErrorFunction < [ unknown ] > = ( c , title ) =>
0 commit comments