File tree Expand file tree Collapse file tree
packages/dom/src/lib/helpers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,24 +79,28 @@ function normalizeText(text: string): string {
7979}
8080
8181export function getAccessibleDescription ( actual : Element ) : string {
82- const ariaDescribedBy = actual . getAttribute ( "aria-describedby" ) || "" ;
83- const descriptionIds = ariaDescribedBy
84- . split ( / \s + / )
85- . filter ( Boolean ) ;
86-
87- if ( descriptionIds . length === 0 ) {
82+ const ariaDescribedBy = actual . getAttribute ( "aria-describedby" ) ;
83+
84+ if ( ! ariaDescribedBy ) {
8885 return "" ;
8986 }
87+
88+ const descriptionIds = ariaDescribedBy . split ( / \s + / ) . filter ( Boolean ) ;
9089
9190 const getElementText = ( id : string ) : string | null => {
9291 const element = actual . ownerDocument . getElementById ( id ) ;
93- return element ?. textContent || null ;
92+
93+ if ( ! element || ! element . textContent ) {
94+ return null ;
95+ }
96+
97+ return element . textContent ;
9498 } ;
9599
96- return normalizeText (
97- descriptionIds
98- . map ( getElementText )
99- . filter ( ( text ) : text is string => text !== null )
100- . join ( " " ) ,
101- ) ;
100+ const combinedText = descriptionIds
101+ . map ( getElementText )
102+ . filter ( ( text ) : text is string => text !== null )
103+ . join ( " " ) ;
104+
105+ return normalizeText ( combinedText ) ;
102106}
You can’t perform that action at this time.
0 commit comments