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

Fixed : Modal dialog: small improvement for elementShouldBeHidden #65941

Merged
merged 11 commits into from
Oct 14, 2024
Merged
2 changes: 1 addition & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased

### Bug Fixes

- `Modal` : Modal dialog small improvement for elementShouldBeHidden - PR ([#65941](https://github.com/WordPress/gutenberg/pull/65941)).
Copy link
Contributor

Choose a reason for hiding this comment

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

The changelog entry should follow a specific format:

  • Please remove the space before the colon.
  • Please remove the - PR .
  • I'd consider to move the entry to the Enhancements section as it's not a bug fix.

- `ToolsPanel`: atomic one-step state update when (un)registering panels ([#65564](https://github.com/WordPress/gutenberg/pull/65564)).
- `Navigator`: fix `isInitial` logic ([#65527](https://github.com/WordPress/gutenberg/pull/65527)).

Expand Down
13 changes: 9 additions & 4 deletions packages/components/src/modal/aria-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ export function modalize( modalElement?: HTMLDivElement ) {
*/
export function elementShouldBeHidden( element: Element ) {
const role = element.getAttribute( 'role' );

// Combine the conditions into a single return statement
return ! (
element.tagName === 'SCRIPT' ||
element.hasAttribute( 'aria-hidden' ) ||
element.hasAttribute( 'aria-live' ) ||
( role && LIVE_REGION_ARIA_ROLES.has( role ) )
(
element.tagName === 'SCRIPT' || // Skip <script> tags
element.hasAttribute( 'hidden' ) || // Skip elements with 'hidden' attribute
element.hasAttribute( 'aria-hidden' ) || // Skip elements marked as aria-hidden
element.hasAttribute( 'aria-live' ) || // Skip live regions
( role && LIVE_REGION_ARIA_ROLES.has( role ) )
) // Skip elements with live region roles
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should be moved to the appropriate line. However, I'd consider to remove all these comments because the code is pretty self-explanatory.

);
}

Expand Down