Skip to content

Commit fbe99bf

Browse files
authored
fix(access-name): get name from header elements (#4097)
* fix(dialog-name): get name from header elements * Never get content from elements with a value * Fix failing test * Grrr, prettier * More tests * Update test/testutils.js
1 parent 53c7ee4 commit fbe99bf

File tree

11 files changed

+2255
-1479
lines changed

11 files changed

+2255
-1479
lines changed

lib/commons/text/form-control-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import isHiddenForEveryone from '../dom/is-hidden-for-everyone';
1313
import { nodeLookup, querySelectorAll } from '../../core/utils';
1414
import log from '../../core/log';
1515

16-
const controlValueRoles = [
16+
export const controlValueRoles = [
1717
'textbox',
1818
'progressbar',
1919
'scrollbar',

lib/commons/text/subtree-text.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import accessibleTextVirtual from './accessible-text-virtual';
22
import namedFromContents from '../aria/named-from-contents';
33
import getOwnedVirtual from '../aria/get-owned-virtual';
4+
import getRole from '../aria/get-role';
45
import getElementsByContentType from '../standards/get-elements-by-content-type';
56
import getElementSpec from '../standards/get-element-spec';
7+
import { controlValueRoles } from './form-control-value';
68

79
/**
810
* Get the accessible text for an element that can get its name from content
@@ -16,20 +18,23 @@ function subtreeText(virtualNode, context = {}) {
1618
const { alreadyProcessed } = accessibleTextVirtual;
1719
context.startNode = context.startNode || virtualNode;
1820
const { strict, inControlContext, inLabelledByContext } = context;
21+
const role = getRole(virtualNode);
1922
const { contentTypes } = getElementSpec(virtualNode, {
2023
noMatchAccessibleName: true
2124
});
2225
if (
2326
alreadyProcessed(virtualNode, context) ||
2427
virtualNode.props.nodeType !== 1 ||
25-
contentTypes?.includes('embedded') // canvas, video, etc
28+
contentTypes?.includes('embedded') || // canvas, video, etc
29+
controlValueRoles.includes(role)
2630
) {
2731
return '';
2832
}
2933

3034
if (
31-
!namedFromContents(virtualNode, { strict }) &&
32-
!context.subtreeDescendant
35+
!context.subtreeDescendant &&
36+
!context.inLabelledByContext &&
37+
!namedFromContents(virtualNode, { strict })
3338
) {
3439
return '';
3540
}
@@ -40,6 +45,7 @@ function subtreeText(virtualNode, context = {}) {
4045
* chosen to ignore this, but only for direct content, not for labels / aria-labelledby.
4146
* That way in `a[href] > article > #text` the text is used for the accessible name,
4247
* See: https://github.com/dequelabs/axe-core/issues/1461
48+
* See: https://github.com/w3c/accname/issues/120
4349
*/
4450
if (!strict) {
4551
const subtreeDescendant = !inControlContext && !inLabelledByContext;

lib/commons/text/unsupported.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const unsupported = {
2-
accessibleNameFromFieldValue: ['combobox', 'listbox', 'progressbar']
1+
export default {
2+
// Element's who's value is not consistently picked up in the accessible name
3+
// Supported in Chrome 114, Firefox 115, but not Safari 16.5:
4+
// <input aria-labelledby="lbl">
5+
// <div id="lbl" role="progressbar" aria-valuenow="23"></div>
6+
accessibleNameFromFieldValue: ['progressbar']
37
};
4-
5-
export default unsupported;

0 commit comments

Comments
 (0)