Button elements that should be hidden with the js.hidden CSS class are not being hidden in the off-canvas dialog. In particular the image field's 'Upload' button.

Here's how we found it:
1. Created a custom block type with an image field.
2. Set a content type to use Layout Builder.
3. Used the Layout Builder to 'Add Custom Block' and chose the custom block type.
4. The image field shows an Upload button that should be hidden.

The problem is a CSS rule in core/misc/dialog/off-canvas.reset.css on line 248. Core correctly applies a class (js-hide) to set display: none, but the drupal-off-canvas css overrides it so it shows up.

from js.module.css:10

.js .js-hide {
    display: none;
}

from off-canvas-reset.css:244

#drupal-off-canvas button,
#drupal-off-canvas input[type="reset"],
#drupal-off-canvas input[type="submit"],
#drupal-off-canvas input[type="button"] {
  display: inline-block;
  overflow: visible;
  cursor: pointer;
  vertical-align: middle;
  text-decoration: none;
  border: 0;
  outline: 0;
  background-image: none;
  text-shadow: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

display: inline-block is overriding display: none in core/modules/system/css/components/js.module.css

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sacarney created an issue. See original summary.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pyrello’s picture

I can confirm this is an issue. With the media library widget, there is a button that is supposed to be hidden labeled "Update widget", but the button shows.

Only local images are allowed.

It seems like this is maybe a matter of the order in which the CSS files are being loaded.

lauriii’s picture

I know using !important is an anti-pattern most of the time. However, I think this could be a valid place to use it. We don't want element styles accidentally overriding the .js-hide styles since if the class exists and the browser doesn't have JavaScript, the element should be always hidden. If they don't want to hide the element based on that rule, they should remove the class from the element.

Before:

After:

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

komlenic’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that the patch in #4 fixes this, and I have encountered no unexpected side effects.

In my use case, this issue is encountered with adding a Media Library Form API Element to the off-canvas dialog. An "Update widget" button is incorrectly shown that is otherwise hidden on any other forms where this form element is used.

Since this is such a simple fix that is unlikely to cause any issues elsewhere, moving to RTBC.

lauriii’s picture

Extending changes to stable9 because it didn't exist at the time I worked on #4.

jungle’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Needs review

Patch #7 failed to apply. But it seems valid to 9.1.x, queued against 9.1.x. Should we change the target version to 9.1.x? Changing the target version, feel free to change back.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Moving back to RTBC because the patch applies against 9.1.x

larowlan’s picture

Crediting @sacarney who provided a detailed issue summary when reporting this issue 🏆 - thanks!

  • larowlan committed 52fedda on 9.1.x
    Issue #3070375 by lauriii, sacarney: Hidden buttons in off-canvas dialog...

  • larowlan committed 69c0c11 on 9.0.x
    Issue #3070375 by lauriii, sacarney: Hidden buttons in off-canvas dialog...
larowlan’s picture

Title: Hidden buttons in off-canvas dialog are not being hidden » [backport] Hidden buttons in off-canvas dialog are not being hidden
Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Bug Smash Initiative, +Needs reroll

I agree that using !important stinks, but given a) @lauriii is the FE FM and b) we don't have many other options because so much of the CSS in off-canvas is way too specific, committing this is.

As someone who has fought against the css in off-canvas on every project, I feel like we need a follow-up here to make it use BEM instead of IDs (which is the source of our specificity woes I suspect). Is there an existing issue? If not can you create one @lauriii?

I kid you not, our starter themes at PNX have a libraries-override definition to remove all of the core CSS for that component and a reasonable starter CSS file for something that doesn't clobber all of your styles and allows easy extension when things go wrong - nice to see this button issue fixed in core.

Committed 52fedda and pushed to 9.1.x. Thanks!

Because the risk of disruption here is low, backported to 9.0.x - 8.9x doesn't apply - reassigning and tagging for that.

jungle’s picture

Status: Patch (to be ported) » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
485 bytes
868 bytes
221 bytes

@larowlan, thanks for commiting!

error: core/themes/stable9/css/system/components/js.module.css: No such file or directory
$ git grep ".js .js-hide"
core/modules/system/css/components/js.module.css:.js .js-hide {
core/themes/stable/css/system/components/js.module.css:.js .js-hide {

Assuming testing passes.

jungle’s picture

raw-interdiff-26-35.txt should not be in #14, sorry!

lauriii’s picture

Re #13: CSS in off-canvas was deliberately made to use way too specific CSS in #2826722: Add a 'fence' around settings tray with aggressive CSS reset. to make it compatible with as many pre-existing themes as possible. I agree that the current solution is not ideal. We've been planning a new strategy in #2195695: Admin UIs on the front-end are difficult to theme. However, it doesn't seem like the proposed plan there would be something that could be implemented overnight.

  • larowlan committed 3d7f169 on 8.9.x
    Issue #3070375 by lauriii, jungle, larowlan, sacarney: [backport] Hidden...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Backported this to 8.9.x

Committed 3d7f169 and pushed to 8.9.x. Thanks!

Thanks @lauriii for the linked issue

jungle’s picture

Title: [backport] Hidden buttons in off-canvas dialog are not being hidden » Hidden buttons in off-canvas dialog are not being hidden
chr.fritsch’s picture

  • lauriii committed 184a612 on 9.1.x
    Revert "Issue #3070375 by lauriii, jungle, larowlan, sacarney: [backport...
lauriii’s picture

Status: Fixed » Needs work

It seems like we should use similar approach to #3166068: Autocomplete "loading" message not properly hidden in inline forms here because of this runs into some issues with the way jQuery .show and .hide works. We could reconsider this approach after #3167377: Rewrite jQuery .show() and .hide().

  • lauriii committed 0a3545b on 9.0.x
    Revert "Issue #3070375 by lauriii, sacarney: Hidden buttons in off-...

  • lauriii committed 924d583 on 8.9.x
    Revert "Issue #3070375 by lauriii, jungle, larowlan, sacarney: [backport...

  • lauriii committed 4c3744d on 9.1.x
    Revert "Revert "Issue #3070375 by lauriii, jungle, larowlan, sacarney: [...
  • lauriii committed b1fc8e0 on 9.1.x
    Revert "Issue #3070375 by lauriii, sacarney: Hidden buttons in off-...
lauriii’s picture

I'm wondering if we have a reliable way to solve this until #3167377: Rewrite jQuery .show() and .hide() has been resolved.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.