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(aria-required-children): do not fail for children with aria-hidden #3949

Merged
merged 2 commits into from
Mar 22, 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
12 changes: 11 additions & 1 deletion lib/checks/aria/aria-required-children-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
getOwnedVirtual
} from '../../commons/aria';
import { getGlobalAriaAttrs } from '../../commons/standards';
import { hasContentVirtual, idrefs, isFocusable } from '../../commons/dom';
import {
hasContentVirtual,
idrefs,
isFocusable,
isVisibleToScreenReaders
} from '../../commons/dom';

/**
* Get all owned roles of an element
Expand All @@ -15,6 +20,10 @@ function getOwnedRoles(virtualNode, required) {
const ownedElements = getOwnedVirtual(virtualNode);
for (let i = 0; i < ownedElements.length; i++) {
const ownedElement = ownedElements[i];
if (ownedElement.props.nodeType !== 1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to ignore non-element nodes as isVisibletoScreenreaders calls into isHiddenForEveryone which tries to get the computed style for display, which fails for non-element nodes

continue;
}

const role = getRole(ownedElement, { noPresentational: true });

const hasGlobalAria = getGlobalAriaAttrs().some(attr =>
Expand All @@ -27,6 +36,7 @@ function getOwnedRoles(virtualNode, required) {
// this means intermediate roles between a required parent and
// child will fail the check
if (
!isVisibleToScreenReaders(ownedElement) ||
(!role && !hasGlobalAriaOrFocusable) ||
(['group', 'rowgroup'].includes(role) &&
required.some(requiredRole => requiredRole === role))
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export { default as isNode } from './is-node';
export { default as isOffscreen } from './is-offscreen';
export { default as isOpaque } from './is-opaque';
export { default as isSkipLink } from './is-skip-link';
export { default as isVisibleToScreenReaders } from './is-visible-for-screenreader';
export { default as isVisibleToScreenReaders } from './is-visible-to-screenreader';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the file names were still using for instead of to so changed those to match the name of the function while I was there.

This comment was marked as spam.

export { default as isVisibleOnScreen } from './is-visible-on-screen';
export { default as isVisible } from './is-visible';
export { default as isVisualContent } from './is-visual-content';
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/text/accessible-text-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import formControlValue from './form-control-value';
import subtreeText from './subtree-text';
import titleText from './title-text';
import sanitize from './sanitize';
import isVisibleToScreenReaders from '../dom/is-visible-for-screenreader';
import isVisibleToScreenReaders from '../dom/is-visible-to-screenreader';
import isIconLigature from '../text/is-icon-ligature';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/text/visible-virtual.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sanitize from './sanitize';
import isVisibleOnScreen from '../dom/is-visible-on-screen';
import isVisibleToScreenReaders from '../dom/is-visible-for-screenreader';
import isVisibleToScreenReaders from '../dom/is-visible-to-screenreader';
import AbstractVirtualNode from '../../core/base/virtual-node/abstract-virtual-node';
import { getNodeFromTree } from '../../core/utils';

Expand Down
Loading