Problem/Motivation

Dropbutton JS use the same CSS classes for it's functionality that are used for styling Dropbutton (or Operations).

Proposed resolution

Add CSS classes that are used only for JavaScript functionality.

Remaining tasks

Patch

User interface changes

Nothing

API changes

Nothing

Data model changes

Nothing

Release notes snippet

@todo

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Active » Needs review
StatusFileSize
new5.9 KB

Status: Needs review » Needs work

The last submitted patch, 2: core-dropbutton_js_prefix-3057281-2.patch, failed testing. View results

huzooka’s picture

Assigned: Unassigned » huzooka
huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review
StatusFileSize
new11.04 KB
new8.91 KB
quiron’s picture

I reviewed and tested and looks good to me. I attach a new version with few new catches where the 'js-' class is missing

I'm wondering if https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/langua... should be updated to the new one, as long is more functional than CSS, but not JS. I added it just in case.

Finally is not clear why in some tests is it updated to the prefixed class and some case the other one is kept. I don't change anything in tests as long looks they are passing right now.

wim leers’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Needs review » Needs work
  1. +++ b/core/misc/dropbutton/dropbutton.es6.js
    @@ -3,7 +3,7 @@
    -(function($, Drupal) {
    +(($, Drupal) => {
    

    🤓 Übernit: This seems out of scope to change.

  2. +++ b/core/misc/dropbutton/dropbutton.es6.js
    @@ -36,7 +36,7 @@
    -    this.$list = $dropbutton.find('.dropbutton');
    +    this.$list = $dropbutton.find('.js-dropbutton');
    

    ✅ 😨 This looks like a big BC break! — see next point 😅

  3. +++ b/core/misc/dropbutton/dropbutton.js
    @@ -94,7 +94,7 @@
    -      return '<li class="dropbutton-toggle"><button type="button"><span class="dropbutton-arrow"><span class="visually-hidden">' + options.title + '</span></span></button></li>';
    +      return '<li class="dropbutton-toggle js-dropbutton-toggle"><button type="button"><span class="dropbutton-arrow"><span class="visually-hidden">' + options.title + '</span></span></button></li>';
    
    +++ b/core/modules/book/tests/src/Functional/BookTest.php
    @@ -504,7 +504,7 @@ public function testAdminBookNodeListing() {
    -    $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a');
    +    $elements = $this->xpath('//table//ul[@class="dropbutton js-dropbutton"]/li/a');
    

    👍 This proves that there is no BC break: the old classes continues to exist, we're only adding new ones!

  4. +++ b/core/modules/language/config/optional/tour.tour.language.yml
    @@ -44,7 +44,7 @@ tips:
    -      data-class: dropbutton-wrapper
    +      data-class: js-dropbutton-wrapper
    

    😲First reaction: wow, incredible that you thought of the selectors in tours! :D

    🤔 Second reaction: The old class continues to exist, so why this change? Even if it's harmless, tours are config entities, and those are not updated automatically, so this opens a can of worms wrt updating tours that I'd rather avoid :)

All easy things to fix, once those are fixed, this will be an easy RTBC :) Nice work!

fhaeberle’s picture

A reroll was needed to apply the patch from #6 because in the meanwhile there where some changes.
Applied all suggestions from #7. Thank you for the review! :)

wim leers’s picture

Status: Needs review » Needs work

I really wanted to RTBC this. The second point is so minor I could've RTBC'd, but the first one needs to be reverted or at least needs to be justified.

  1. +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
    @@ -233,8 +233,8 @@ protected function doTestTranslationOverview() {
    -        $this->assertEqual((string) $elements[0], t('Edit'), new FormattableMarkup('Edit link correct for %language translation.', ['%language' => $langcode]));
    ...
    +        $this->assertEqual((string) $elements[0], t('Edit'), format_string('Edit link correct for %language translation.', ['%language' => $langcode]));
    

    🤔 Why this change? That did not exist in #6.

  2. +++ b/core/modules/views_ui/js/views-admin.js
    @@ -628,4 +628,4 @@
    -})(jQuery, Drupal, drupalSettings);
    \ No newline at end of file
    +})(jQuery, Drupal, drupalSettings);
    

    🤓 Übernit: this change was probably applied by your IDE/text editor, but we should revert it nonetheless.

fhaeberle’s picture

I corrected your suggestions! :)
The new line was introduced in #6, I also checked my IDE. Thanks for pointing that out!

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Perfect! Ship it :) 🚢

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record
+++ b/core/modules/system/templates/dropbutton-wrapper.html.twig
@@ -13,7 +13,7 @@
 #}
 {% if children %}
   {% spaceless %}
-    <div class="dropbutton-wrapper">
+    <div class="dropbutton-wrapper js-dropbutton-wrapper">
       <div class="dropbutton-widget">
         {{ children }}
       </div>

+++ b/core/modules/views_ui/src/ViewEditForm.php
index ca68716db2..0bbc877154 100644
--- a/core/themes/classy/templates/form/dropbutton-wrapper.html.twig

--- a/core/themes/classy/templates/form/dropbutton-wrapper.html.twig
+++ b/core/themes/classy/templates/form/dropbutton-wrapper.html.twig

+++ b/core/themes/classy/templates/form/dropbutton-wrapper.html.twig
@@ -11,7 +11,7 @@
 {% if children %}
   {% spaceless %}
-    <div class="dropbutton-wrapper">
+    <div class="dropbutton-wrapper js-dropbutton-wrapper">
       <div class="dropbutton-widget">

+++ b/core/themes/stable/templates/form/dropbutton-wrapper.html.twig
@@ -11,7 +11,7 @@
 {% if children %}
   {% spaceless %}
-    <div class="dropbutton-wrapper">
+    <div class="dropbutton-wrapper js-dropbutton-wrapper">
       <div class="dropbutton-widget">
         {{ children }}
       </div>

I wonder if these changes are going to result in regressions for themes. It looks as some do override this markup - see http://codcontrib.hank.vps-private.net/search?text=dropbutton-wrapper&fi... - for example https://git.drupalcode.org/project/material_admin/blob/8.x-1.x/templates...

I think we need a change record here but maybe also we need to think about a different approach that is less disruptive? Going to ping @lauriii as a frontend framework manager.

wim leers’s picture

Going to ping @lauriii as a frontend framework manager.

alexpott 59 minutes ago
@lauriii Am I on the wrong track here - https://www.drupal.org/project/drupal/issues/3057281#comment-13268776

lauriii  42 minutes ago
I think you’re right

lauriii  42 minutes ago
there’s a high risk of regression there

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

fhaeberle’s picture

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sakthivel m’s picture

Status: Needs review » Needs work

#10 Patch Failed

sakthivel m’s picture

Status: Needs work » Needs review
StatusFileSize
new11.72 KB

#20 Please review the patch

Status: Needs review » Needs work

The last submitted patch, 20: 3057281.20.patch, failed testing. View results

sakthivel m’s picture

Status: Needs work » Needs review
andy-blum’s picture

Status: Needs review » Needs work

Patch #20 failed the tests and doesn't apply.

I am curious about the cost/benefit of this change. If it's such a huge potential source for BC-breaking changes, what benefits are we getting besides a separation of classes for styles & scripts? Is it still worth doing?

If the changes are still worth making, do we actually need to update the various test files that are contained in previous patches? Shouldn't xpath('//table//ul[@class="dropbutton"]/li/a') work just as well as xpath('//table//ul[@class="dropbutton js-dropbutton"]/li/a')?

ankithashetty’s picture

Status: Needs work » Needs review
StatusFileSize
new11.7 KB
new2.05 KB

Just re-rolled the patch in #20, thanks!

Status: Needs review » Needs work

The last submitted patch, 24: 3057281-24.patch, failed testing. View results

andy-blum’s picture

I've never written tests, but it looks like this is failing because my assumption in #23 is incorrect.

After applying the patch in #24, line 649 fails. Line 648 is checking the dropbutton elements to count how many book pages exist and is using xpath('//table//ul[@class="dropbutton"]/li/a') to do so. It looks like there is another instance we need to add js-dropbutton in line 659 as well.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.