@@ -9,10 +9,6 @@ const elementRolesMap = new ObjectMap()
9
9
for ( const [ key , value ] of elementRoles . entries ( ) ) {
10
10
// - Remove unused `constraints` key
11
11
delete key . constraints
12
- // - Remove `constraints` key within `attributes`
13
- for ( const attribute of key . attributes || [ ] ) {
14
- delete attribute . constraints
15
- }
16
12
// - Remove empty `attributes` key
17
13
if ( ! key . attributes || key . attributes ?. length === 0 ) {
18
14
delete key . attributes
@@ -44,14 +40,31 @@ module.exports = {
44
40
// - Get the element’s name
45
41
const key = { name : getElementType ( context , node ) }
46
42
// - 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
+
48
59
const value = getPropValue ( getProp ( node . attributes , prop ) )
49
60
if ( value ) {
50
61
if ( ! ( 'attributes' in key ) ) {
51
62
key . attributes = [ ]
52
63
}
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' ] } )
55
68
} else {
56
69
key . attributes . push ( { name : prop , value} )
57
70
}
0 commit comments