Skip to content

Commit

Permalink
Use explicit check for VisuallyHidden
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks authored and ramonjd committed Aug 22, 2024
1 parent 0ed777f commit c7cd7aa
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/block-editor/src/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,21 @@ function isElementVisible( element ) {
return false;
}

const style = viewport.getComputedStyle( element );
if (
style.display === 'none' ||
style.visibility === 'hidden' ||
style.opacity === '0'
) {
// Check for <VisuallyHidden> component.
if ( element.classList.contains( 'components-visually-hidden' ) ) {
return false;
}

const bounds = element.getBoundingClientRect();

if ( bounds.width === 0 || bounds.height === 0 ) {
return false;
}

// wp-components visually hides elements by setting their width and
// height to 1px and positioning them off-screen.
const style = viewport.getComputedStyle( element );
if (
bounds.width === 1 &&
bounds.height === 1 &&
( bounds.left < 0 || bounds.top < 0 )
style.display === 'none' ||
style.visibility === 'hidden' ||
style.opacity === '0'
) {
return false;
}
Expand Down

0 comments on commit c7cd7aa

Please sign in to comment.