@@ -15,10 +15,11 @@ const ID_DELIMITER = ' ';
15
15
*/
16
16
export function addAriaReferencedId ( el : Element , attr : `aria-${string } `, id : string ) {
17
17
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 ) ) {
19
20
return ;
20
21
}
21
- ids . push ( id . trim ( ) ) ;
22
+ ids . push ( id ) ;
22
23
23
24
el . setAttribute ( attr , ids . join ( ID_DELIMITER ) ) ;
24
25
}
@@ -29,7 +30,8 @@ export function addAriaReferencedId(el: Element, attr: `aria-${string}`, id: str
29
30
*/
30
31
export function removeAriaReferencedId ( el : Element , attr : `aria-${string } `, id : string ) {
31
32
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 ) ;
33
35
34
36
if ( filteredIds . length ) {
35
37
el . setAttribute ( attr , filteredIds . join ( ID_DELIMITER ) ) ;
@@ -44,5 +46,6 @@ export function removeAriaReferencedId(el: Element, attr: `aria-${string}`, id:
44
46
*/
45
47
export function getAriaReferenceIds ( el : Element , attr : string ) : string [ ] {
46
48
// 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) ?? [ ] ;
48
51
}
0 commit comments