Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(access-name): get name from header elements #4097

Merged
merged 7 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/commons/text/form-control-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import isHiddenForEveryone from '../dom/is-hidden-for-everyone';
import { nodeLookup, querySelectorAll } from '../../core/utils';
import log from '../../core/log';

const controlValueRoles = [
export const controlValueRoles = [
'textbox',
'progressbar',
'scrollbar',
Expand Down
12 changes: 9 additions & 3 deletions lib/commons/text/subtree-text.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import accessibleTextVirtual from './accessible-text-virtual';
import namedFromContents from '../aria/named-from-contents';
import getOwnedVirtual from '../aria/get-owned-virtual';
import getRole from '../aria/get-role';
import getElementsByContentType from '../standards/get-elements-by-content-type';
import getElementSpec from '../standards/get-element-spec';
import { controlValueRoles } from './form-control-value';

/**
* Get the accessible text for an element that can get its name from content
Expand All @@ -16,20 +18,23 @@ function subtreeText(virtualNode, context = {}) {
const { alreadyProcessed } = accessibleTextVirtual;
context.startNode = context.startNode || virtualNode;
const { strict, inControlContext, inLabelledByContext } = context;
const role = getRole(virtualNode);
const { contentTypes } = getElementSpec(virtualNode, {
noMatchAccessibleName: true
});
if (
alreadyProcessed(virtualNode, context) ||
virtualNode.props.nodeType !== 1 ||
contentTypes?.includes('embedded') // canvas, video, etc
contentTypes?.includes('embedded') || // canvas, video, etc
controlValueRoles.includes(role)
) {
return '';
}

if (
!namedFromContents(virtualNode, { strict }) &&
!context.subtreeDescendant
!context.subtreeDescendant &&
!context.inLabelledByContext &&
!namedFromContents(virtualNode, { strict })
) {
return '';
}
Expand All @@ -40,6 +45,7 @@ function subtreeText(virtualNode, context = {}) {
* chosen to ignore this, but only for direct content, not for labels / aria-labelledby.
* That way in `a[href] > article > #text` the text is used for the accessible name,
* See: https://github.com/dequelabs/axe-core/issues/1461
* See: https://github.com/w3c/accname/issues/120
*/
if (!strict) {
const subtreeDescendant = !inControlContext && !inLabelledByContext;
Expand Down
10 changes: 6 additions & 4 deletions lib/commons/text/unsupported.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const unsupported = {
accessibleNameFromFieldValue: ['combobox', 'listbox', 'progressbar']
export default {
// Element's who's value is not consistently picked up in the accessible name
// Supported in Chrome 114, Firefox 115, but not Safari 16.5:
// <input aria-labelledby="lbl">
// <div id="lbl" role="progressbar" aria-valuenow="23"></div>
accessibleNameFromFieldValue: ['progressbar']
WilcoFiers marked this conversation as resolved.
Show resolved Hide resolved
};

export default unsupported;
Loading