@@ -15,10 +15,11 @@ const ID_DELIMITER = ' ';
1515 */
1616export function addAriaReferencedId ( el : Element , attr : `aria-${string } `, id : string ) {
1717 const ids = getAriaReferenceIds ( el , attr ) ;
18- if ( ids . some ( existingId => existingId . trim ( ) == id . trim ( ) ) ) {
18+ id = id . trim ( ) ;
19+ if ( ids . some ( existingId => existingId . trim ( ) === id ) ) {
1920 return ;
2021 }
21- ids . push ( id . trim ( ) ) ;
22+ ids . push ( id ) ;
2223
2324 el . setAttribute ( attr , ids . join ( ID_DELIMITER ) ) ;
2425}
@@ -29,7 +30,8 @@ export function addAriaReferencedId(el: Element, attr: `aria-${string}`, id: str
2930 */
3031export function removeAriaReferencedId ( el : Element , attr : `aria-${string } `, id : string ) {
3132 const ids = getAriaReferenceIds ( el , attr ) ;
32- const filteredIds = ids . filter ( val => val != id . trim ( ) ) ;
33+ id = id . trim ( ) ;
34+ const filteredIds = ids . filter ( val => val !== id ) ;
3335
3436 if ( filteredIds . length ) {
3537 el . setAttribute ( attr , filteredIds . join ( ID_DELIMITER ) ) ;
@@ -44,5 +46,6 @@ export function removeAriaReferencedId(el: Element, attr: `aria-${string}`, id:
4446 */
4547export function getAriaReferenceIds ( el : Element , attr : string ) : string [ ] {
4648 // Get string array of all individual ids (whitespace delimited) in the attribute value
47- return ( el . getAttribute ( attr ) || '' ) . match ( / \S + / g) || [ ] ;
49+ const attrValue = el . getAttribute ( attr ) ;
50+ return attrValue ?. match ( / \S + / g) ?? [ ] ;
4851}
0 commit comments