1
1
import accessibleTextVirtual from './accessible-text-virtual' ;
2
2
import namedFromContents from '../aria/named-from-contents' ;
3
3
import getOwnedVirtual from '../aria/get-owned-virtual' ;
4
+ import getRole from '../aria/get-role' ;
4
5
import getElementsByContentType from '../standards/get-elements-by-content-type' ;
5
6
import getElementSpec from '../standards/get-element-spec' ;
7
+ import { controlValueRoles } from './form-control-value' ;
6
8
7
9
/**
8
10
* Get the accessible text for an element that can get its name from content
@@ -16,20 +18,23 @@ function subtreeText(virtualNode, context = {}) {
16
18
const { alreadyProcessed } = accessibleTextVirtual ;
17
19
context . startNode = context . startNode || virtualNode ;
18
20
const { strict, inControlContext, inLabelledByContext } = context ;
21
+ const role = getRole ( virtualNode ) ;
19
22
const { contentTypes } = getElementSpec ( virtualNode , {
20
23
noMatchAccessibleName : true
21
24
} ) ;
22
25
if (
23
26
alreadyProcessed ( virtualNode , context ) ||
24
27
virtualNode . props . nodeType !== 1 ||
25
- contentTypes ?. includes ( 'embedded' ) // canvas, video, etc
28
+ contentTypes ?. includes ( 'embedded' ) || // canvas, video, etc
29
+ controlValueRoles . includes ( role )
26
30
) {
27
31
return '' ;
28
32
}
29
33
30
34
if (
31
- ! namedFromContents ( virtualNode , { strict } ) &&
32
- ! context . subtreeDescendant
35
+ ! context . subtreeDescendant &&
36
+ ! context . inLabelledByContext &&
37
+ ! namedFromContents ( virtualNode , { strict } )
33
38
) {
34
39
return '' ;
35
40
}
@@ -40,6 +45,7 @@ function subtreeText(virtualNode, context = {}) {
40
45
* chosen to ignore this, but only for direct content, not for labels / aria-labelledby.
41
46
* That way in `a[href] > article > #text` the text is used for the accessible name,
42
47
* See: https://github.com/dequelabs/axe-core/issues/1461
48
+ * See: https://github.com/w3c/accname/issues/120
43
49
*/
44
50
if ( ! strict ) {
45
51
const subtreeDescendant = ! inControlContext && ! inLabelledByContext ;
0 commit comments