File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
src/internal/analytics-metadata Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,22 @@ describe('getLabelFromElement', () => {
9393 const target = container . querySelector ( '#target' ) ;
9494 expect ( getLabelFromElement ( target as HTMLElement ) ) . toEqual ( '' ) ;
9595 } ) ;
96+ test ( 'trims the label' , ( ) => {
97+ const { container } = render (
98+ < div >
99+ < div id = "target1" aria-label = " abcd efg " >
100+ content
101+ </ div >
102+ < div id = "target2" >
103+ { ' ' } content{ ' ' }
104+ </ div >
105+ </ div >
106+ ) ;
107+ const target1 = container . querySelector ( '#target1' ) ;
108+ expect ( getLabelFromElement ( target1 as HTMLElement ) ) . toEqual ( 'abcd efg' ) ;
109+ const target2 = container . querySelector ( '#target2' ) ;
110+ expect ( getLabelFromElement ( target2 as HTMLElement ) ) . toEqual ( 'content' ) ;
111+ } ) ;
96112} ) ;
97113
98114describe ( 'processLabel' , ( ) => {
Original file line number Diff line number Diff line change @@ -56,13 +56,13 @@ export const getLabelFromElement = (element: HTMLElement | null): string => {
5656 }
5757 const ariaLabel = element . getAttribute ( 'aria-label' ) ;
5858 if ( ariaLabel ) {
59- return ariaLabel ;
59+ return ariaLabel . trim ( ) ;
6060 }
6161 const ariaLabelledBy = element . getAttribute ( 'aria-labelledby' ) ;
6262 if ( ariaLabelledBy ) {
6363 const elementWithLabel = document . querySelector ( `[id="${ ariaLabelledBy . split ( ' ' ) [ 0 ] } "]` ) ;
6464 return getLabelFromElement ( elementWithLabel as HTMLElement ) ;
6565 }
6666
67- return element . textContent || '' ;
67+ return element . textContent ? element . textContent . trim ( ) : '' ;
6868} ;
You can’t perform that action at this time.
0 commit comments