@@ -9,10 +9,6 @@ const elementRolesMap = new ObjectMap()
99for ( const [ key , value ] of elementRoles . entries ( ) ) {
1010 // - Remove unused `constraints` key
1111 delete key . constraints
12- // - Remove `constraints` key within `attributes`
13- for ( const attribute of key . attributes || [ ] ) {
14- delete attribute . constraints
15- }
1612 // - Remove empty `attributes` key
1713 if ( ! key . attributes || key . attributes ?. length === 0 ) {
1814 delete key . attributes
@@ -44,14 +40,31 @@ module.exports = {
4440 // - Get the element’s name
4541 const key = { name : getElementType ( context , node ) }
4642 // - Get the element’s disambiguating attributes
47- for ( const prop of [ 'type' , 'size' , 'role' , 'href' , 'multiple' , 'scope' ] ) {
43+ for ( const prop of [
44+ 'aria-label' ,
45+ 'aria-labelledby' ,
46+ 'alt' ,
47+ 'type' ,
48+ 'size' ,
49+ 'role' ,
50+ 'href' ,
51+ 'multiple' ,
52+ 'scope' ,
53+ 'name' ,
54+ ] ) {
55+ if ( ( prop === 'aria-labelledby' || prop === 'aria-label' ) && ! [ 'section' , 'aside' , 'form' ] . includes ( key . name ) )
56+ continue
57+ if ( prop === 'name' && key . name !== 'form' ) continue
58+
4859 const value = getPropValue ( getProp ( node . attributes , prop ) )
4960 if ( value ) {
5061 if ( ! ( 'attributes' in key ) ) {
5162 key . attributes = [ ]
5263 }
53- if ( prop === 'href' ) {
54- key . attributes . push ( { name : prop } )
64+ if ( prop === 'href' || prop === 'aria-labelledby' || prop === 'aria-label' ) {
65+ key . attributes . push ( { name : prop , constraints : [ 'set' ] } )
66+ } else if ( prop === 'alt' && value !== '' ) {
67+ key . attributes . push ( { name : prop , constraints : [ 'set' ] } )
5568 } else {
5669 key . attributes . push ( { name : prop , value} )
5770 }
0 commit comments