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:
- Install Drupal 11.x with minimal profile
- Set Claro as the Default theme (not just admin theme)
- Enable ajax_test module (needs
extension_discovery_scan_testssetting) - Visit /ajax-test/dialog
- Click Link 6 (entity form) and notice the missing button background
- Install contextual and toolbar modules and repeat steps 4-5. Since contextual module ultimately loads
claro/claro.jquery.uiin the initial page load, the additional stylesheet is loaded in the correct order and the button is correctly styled.
With standard profile:
- Install Drupal 11.x with standard profile
- Set Claro as the Default theme (not just admin theme)
- Enable ajax_test module (needs
extension_discovery_scan_testssetting) - Visit /ajax-test/dialog
- Click Link 6 (entity form)
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | dialog-fixed.png | 32.6 KB | mstrelan |
| #27 | dialog-broken.png | 32.11 KB | mstrelan |
| #8 | 3383631-7.patch | 1.08 KB | nilesh.k |
| #3 | Screenshot 2023-08-28 at 9.11.05 AM.png | 310.18 KB | gauravvvv |
Issue fork drupal-3383631
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
Comment #2
kelvinwong commentedComment #3
gauravvvv commentedI 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.

Comment #4
kelvinwong commentedUpdate link to repo with the right correct version of Drupal.
Comment #5
kelvinwong commentedRE: #3
That's interesting. What version of Drupal did you perform the test on?
Comment #6
kelvinwong commentedFrom the style of your dialog. I can see the
jquery.ui/theme.cssdid 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.
Comment #7
nilesh.k commentedHi
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

After patch

Comment #8
nilesh.k commentedSorry miss the patch in comment #7, adding the in this comment
Comment #9
smustgrave commentedThere a way to replicate this without a contrib module?
Comment #10
sebasgd commentedI 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.
Comment #11
kelvinwong commentedI am not surprised that happens on other modules. That extra reference to
jquery.ui/theme.cssinjected by Ajax is also the cause in my case.Look at the
core/drupal.dialogdefined in the info.yml, it extends theclaro/claro.jquery.uilibrary.https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...
As a result, whenever the core Drupal dialog is called, it loads the
jquery.ui/theme.cssfile, which sets all the.ui-widgetbackground to none.https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...
In
css/components/jquery.ui/theme.csshttps://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...
Steps to replicate the issue without involvement of contrib modules
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.
Comment #12
kelvinwong commentedLooking at the file description of
jquery.ui/theme.cssin 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-widgetin 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...
Comment #13
kelvinwong commentedI will also recommend pulling in the button styles when jquery ui dialog is used. That will also fix the spacing issues between buttons.
Comment #14
smustgrave commentedCan 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.
Comment #15
kelvinwong commentedProposed resolution is updated in the ticket to match the patch provided in #13.
Comment #16
kelvinwong commentedComment #17
kalash-j commentedI 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
Comment #18
smustgrave commented@KelvinWong tried following the step you gave in #11 and still not able to trigger the problem.
On D11.x and standard profile.
Comment #19
kelvinwong commentedThis will not happen on Drupal 11.x. It is only an issue on Drupal 10.x. In D11 the library
claro/claro.jquery.uiis not included whencore/drupal.dialogis used, and theclaro/claro.jquery.uilibrary 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/...
In Drupal 10.x:
https://git.drupalcode.org/project/drupal/-/blob/10.1.2/core/themes/clar...
Comment #20
smustgrave commentedSo 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
Comment #21
smustgrave commentedActually appears the change mentioned in #19 it's on the 10.1.x branch already too. So think this can be closed.
Comment #22
smustgrave commentedFixed in #3378341: claro.jquery.ui css assets may be added the page multiple times
Comment #23
smustgrave commented@KelvinWong can you confirm. I can move over credit.
Comment #24
kelvinwong commentedI can confirm the button colour issue is now fixed in core.
Comment #25
smustgrave commentedComment #26
mstrelan commentedRe-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-toolbarlibrary which ends up loadingclaro/claro.jquery.uibut the stylesheets are in a different order, sojquery.ui/theme.csstakes precedence over claro'sbutton.css.Comment #27
mstrelan commentedAdded steps to reproduce and updated screenshots without contrib.
Comment #28
mstrelan commentedTested on 11.x and 10.4.x and can reproduce there also.
Comment #29
mstrelan commentedComment #30
mstrelan commentedComment #33
saurav-drupal-dev commentedAdded MR for the 11.x version from #27 patch
Comment #34
saurav-drupal-dev commentedComment #35
smustgrave commentedComment #36
saurav-drupal-dev commentedComment #37
smustgrave commentedWhy put it back into review? Please check the MR and any comments before changing status
Comment #40
mariacha1 commentedI 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.Comment #41
smustgrave commentedleft comments