Skip to content

Commit

Permalink
fix(aria-required-children): do not fail for children with aria-hidden (
Browse files Browse the repository at this point in the history
#3949)

* fix(aria-required-children): do not fail for children with aria-hidden

* es6
  • Loading branch information
straker authored Mar 22, 2023
1 parent 8db2c24 commit 8714d6b
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 99 deletions.
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) {
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';
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

0 comments on commit 8714d6b

Please sign in to comment.