Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291721

Drupal.displace() has incorrect visibility check

$
0
0

Problem/Motivation

In cases where an element has a data-offset-* attribute and is set to display: none; in a stylesheet, Drupal.displace() will incorrectly still treat it as visible despite it very much not being so, because it checks the inline style attribute only:

// If the element is not visible, do consider its dimensions.
if (el.style.display === 'none') {
  continue;
}

This has surfaced when using the new Navigation module, where it sets display: none; in a stylesheet on .admin-toolbar-control-bar, and you end up with unexpected gaps since Drupal.displace() thinks it's visible.

Steps to reproduce

Enable Navigation module. Visit front-end theme were displacement is taken into account, e.g. uses the CSS custom properties. Notice the gap along the top like so:

A screenshot showing an ostensibly hidden Navigation displace element resulting in unexpected gap along the top of the screen.

Proposed resolution

At the very least, getComputedStyle() should be used to get the calculated value rather than just the inline value. For a much more robust solution that actually tries to catch all the ways an element can be considered actually hidden, jQuery's :hidden selector is rather informative.

When switching to getComputedStyle(), the element is correctly ignored and does not affect displacement:

A screenshot showing an ostensibly hidden Navigation displace element not resulting in a gap along the top of the screen.

Remaining tasks

Replace inline style check with getComputedStyle().

User interface changes

No more weird displacement gaps.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

None?


Viewing all articles
Browse latest Browse all 291721

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>