Problem/Motivation

When dialogs are loaded via ajax their primary button is missing the background color if the claro/claro.jquery.ui library has not already been loaded.

The primary button .button--primary should have its background set by the styles in claro/css/components/button.css. If claro/claro.jquery.ui was not already loaded in the initial page load, it gets loaded when the dialog is rendered. This library contains a style for .ui-widget to remove the background color, which has the same specificity as .button--primary. Since the ui-widget style appears later it takes precedence.

Steps to reproduce

With minimal profile:

  1. Install Drupal 11.x with minimal profile
  2. Set Claro as the Default theme (not just admin theme)
  3. Enable ajax_test module (needs extension_discovery_scan_tests setting)
  4. Visit /ajax-test/dialog
  5. Click Link 6 (entity form) and notice the missing button background
  6. Install contextual and toolbar modules and repeat steps 4-5. Since contextual module ultimately loads claro/claro.jquery.ui in the initial page load, the additional stylesheet is loaded in the correct order and the button is correctly styled.

With standard profile:

  1. Install Drupal 11.x with standard profile
  2. Set Claro as the Default theme (not just admin theme)
  3. Enable ajax_test module (needs extension_discovery_scan_tests setting)
  4. Visit /ajax-test/dialog
  5. Click Link 6 (entity form)
  6. Uninstall contextual module and repeat steps 4-5 and notice the missing button background

Without contextual module

With contextual and toolbar modules

Button in DOM
<button type="button" class="button button--primary js-form-submit form-submit ui-button ui-corner-all ui-widget">Save</button>

What we expect
The button to have the button--primary background colour retained.

Proposed resolution

Ensure claro's button.css takes precedence over jquery.ui/theme.css, either by ensuring the order these files are loaded, or by ensuring the button styles have higher specificity than the ui-widget styles.

Issue fork drupal-3383631

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

KelvinWong created an issue. See original summary.

kelvinwong’s picture

Issue summary: View changes
StatusFileSize
new69 KB
gauravvvv’s picture

StatusFileSize
new310.18 KB

I tried reproducing the issue but button is working fine for me. I followed the same steps, please let me know if I am missing something.

kelvinwong’s picture

Issue summary: View changes

Update link to repo with the right correct version of Drupal.

kelvinwong’s picture

RE: #3

That's interesting. What version of Drupal did you perform the test on?

kelvinwong’s picture

From the style of your dialog. I can see the jquery.ui/theme.css did not get loaded. It is likely you are using the Drupal 11.x.

This problem happen to the current latest release of Drupal 10.1.2.

nilesh.k’s picture

Status: Active » Needs review

Hi
as per the last comment i have reproduce issue on my local & created patch for the issue Background colour of UI widgets get overridden on Ajax load, attached the images for reference
Needs review

Before patch
Only local images are allowed.

After patch
Only local images are allowed.

nilesh.k’s picture

StatusFileSize
new1.08 KB

Sorry miss the patch in comment #7, adding the in this comment

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

There a way to replicate this without a contrib module?

sebasgd’s picture

StatusFileSize
new50.19 KB

I also stumbled into this issue, but not with the module described in the ticket. In my case it was with paragraphs.

When the user tries to add a media in the add/edit form, the modal button shows correctly.
But if the user adds a paragraph, from a different field, to the form, then if the user opens de modal again, the button shows with the gray background.

I managed to track a bit the issue. I found that some js libraries are being loaded again when the paragraph was being added to the form. One of the libraries is jquery.ui/theme.css, and this makes it to take more priority in css causing the button issue.

I attached a screenshot of the css file that gets loaded.

kelvinwong’s picture

StatusFileSize
new29.62 KB

I am not surprised that happens on other modules. That extra reference to jquery.ui/theme.css injected by Ajax is also the cause in my case.

Look at the core/drupal.dialog defined in the info.yml, it extends the claro/claro.jquery.ui library.
https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...

  core/drupal.dialog:
    - claro/claro.drupal.dialog
    - claro/claro.jquery.ui

As a result, whenever the core Drupal dialog is called, it loads the jquery.ui/theme.css file, which sets all the .ui-widget background to none.
https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...

claro.jquery.ui:
  version: VERSION
  css:
    component:
      css/components/jquery.ui/theme.css: { weight: -1 }

In css/components/jquery.ui/theme.css
https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...

.ui-widget {
  background: none;
}

Steps to replicate the issue without involvement of contrib modules

  • Set Claro as the default theme, such that both the frontend and admin theme are Claro.
  • Create a basic page content with the following content in body field, you may need to switch to Full HTML in text format.
    <p>
        <a class="use-ajax" href="/node/add/page" data-dialog-options="{&quot;width&quot;:600}" data-dialog-type="modal">Create basic page in modal dialog.</a>
    </p>
    

After saving the page, try clicking on the "Create basic page in modal dialog" link, and you will see the save button is losing its primary button colour inside the model.

kelvinwong’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new834 bytes

Looking at the file description of jquery.ui/theme.css in the theme, this css file is meant to override the styles in /core/assets/vendor/jquery.ui/themes/base/theme.css.

However, I couldn't find any background set up with .ui-widget in the core css file. My recommendation to fix the problem is to get rid of the background none in the theme style, as the css rule is redundant from my point of view.

jquery.ui/theme.css
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/themes/clar...

/core/assets/vendor/jquery.ui/themes/base/theme.css
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/assets/vend...

kelvinwong’s picture

I will also recommend pulling in the button styles when jquery ui dialog is used. That will also fix the spacing issues between buttons.

smustgrave’s picture

Version: 10.1.x-dev » 11.x-dev
Status: Needs review » Needs work

Can the issue summary be updated to include full solution. Current IS talks about pulling in button.css but patch #13 also is removing some css.

kelvinwong’s picture

Issue summary: View changes

Proposed resolution is updated in the ticket to match the patch provided in #13.

kelvinwong’s picture

Status: Needs work » Needs review
kalash-j’s picture

StatusFileSize
new351.52 KB

I have installed 'drupal/scheduled_transitions:^2.3' this version of the module and i tried to reproduce the issue but i am not facing any problem as mentioned above its working fine

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

@KelvinWong tried following the step you gave in #11 and still not able to trigger the problem.

On D11.x and standard profile.

kelvinwong’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Postponed (maintainer needs more info) » Needs review

This will not happen on Drupal 11.x. It is only an issue on Drupal 10.x. In D11 the library claro/claro.jquery.ui is not included when core/drupal.dialog is used, and the claro/claro.jquery.ui library is what pulling in the css style with background none.

Compare the library extend set up in D10 and D11:

In Drupal 11.x:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/themes/claro/...

libraries-extend:
...
  core/drupal.dialog:
    - claro/claro.drupal.dialog

In Drupal 10.x:
https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...

libraries-extend:
...
  core/drupal.dialog:
    - claro/claro.drupal.dialog
    - claro/claro.jquery.ui

smustgrave’s picture

So 11.x is just the main branch now. 10.2 will be tagged from that. So sounds like this will be fixed. Should find the issue it was fixed in and see why it wasn’t backported to 10.1

smustgrave’s picture

Actually appears the change mentioned in #19 it's on the 10.1.x branch already too. So think this can be closed.

smustgrave’s picture

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

@KelvinWong can you confirm. I can move over credit.

kelvinwong’s picture

I can confirm the button colour issue is now fixed in core.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
mstrelan’s picture

Status: Closed (duplicate) » Active

Re-opening this as it's still an issue in 10.3. Steps to reproduce are the same but you must have the contextual module uninstalled. I believe it ultimately comes down to the contextual/drupal.contextual-toolbar library which ends up loading claro/claro.jquery.ui but the stylesheets are in a different order, so jquery.ui/theme.css takes precedence over claro's button.css.

mstrelan’s picture

Version: 10.1.x-dev » 10.3.x-dev
Issue summary: View changes
StatusFileSize
new32.11 KB
new32.6 KB

Added steps to reproduce and updated screenshots without contrib.

mstrelan’s picture

Version: 10.3.x-dev » 11.x-dev
Issue summary: View changes

Tested on 11.x and 10.4.x and can reproduce there also.

mstrelan’s picture

Issue summary: View changes
mstrelan’s picture

Issue summary: View changes

saurav-drupal-dev made their first commit to this issue’s fork.

saurav-drupal-dev’s picture

Added MR for the 11.x version from #27 patch

saurav-drupal-dev’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
saurav-drupal-dev’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Why put it back into review? Please check the MR and any comments before changing status

mariacha1 made their first commit to this issue’s fork.

mariacha1’s picture

Status: Needs work » Needs review

I rerolled the patch and added a Merge Request for 10.5.x because I needed it. I'm not 100% sure that the lines that remove the "background: none" are needed (adding css/components/button.css: {} was all I needed) so I'm curious if other folks find the same thing.

smustgrave’s picture

Status: Needs review » Needs work

left comments

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.