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(is-hidden-for-everyone): count elements inside closed details as hidden #3726

Merged
merged 3 commits into from
Oct 17, 2022
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
10 changes: 8 additions & 2 deletions lib/commons/dom/is-hidden-for-everyone.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import {
nativelyHidden,
displayHidden,
visibilityHidden,
contentVisibiltyHidden
contentVisibiltyHidden,
detailsHidden
} from './visibility-methods';

const hiddenMethods = [displayHidden, visibilityHidden, contentVisibiltyHidden];
const hiddenMethods = [
displayHidden,
visibilityHidden,
contentVisibiltyHidden,
detailsHidden
];

/**
* Determine if an element is hidden from screenreaders and visual users
Expand Down
22 changes: 22 additions & 0 deletions lib/commons/dom/visibility-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,25 @@ export function areaHidden(vNode, visibleFunction) {

return refs.some(ref => !visibleFunction(ref));
}

/**
* Determine if element inside `details` is hidden
*/
export function detailsHidden(vNode) {
if (vNode.parent?.props.nodeName !== 'details') {
return false;
}

// first summary element is never hidden (subsequent ones are though)
if (vNode.props.nodeName === 'summary') {
const firstSummary = vNode.parent.children.find(
node => node.props.nodeName === 'summary'
);

if (firstSummary === vNode) {
return false;
}
}

return !vNode.parent.hasAttr('open');
}
6 changes: 4 additions & 2 deletions lib/core/_exposed-for-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
scrollHidden,
overflowHidden,
clipHidden,
areaHidden
areaHidden,
detailsHidden
} from '../commons/dom/visibility-methods';

const _thisWillBeDeletedDoNotUse = {
Expand Down Expand Up @@ -71,7 +72,8 @@ const _thisWillBeDeletedDoNotUse = {
scrollHidden,
overflowHidden,
clipHidden,
areaHidden
areaHidden,
detailsHidden
}
}
};
Expand Down
Loading