This is a follow-up to #3032365: Table drag style update and #3023326: Field Cardinality Style Update.

Problem/Motivation

Claro originally had to fully replace the objects defined in core/misc/tabledrag.js to fix some bugs in the original asset and make it possible to implment the Claro designs.

When the following core issues are resolved, most of the core-replacing code in Claro can be removed.

Most of this can now be achieved with a set of customized Drupal.theme JavaScript functions, but two requirements must be achieved differently:

  • The markChanged: override must remain as adding these changes to core have potential BC issues that make it difficult to land the core issue: #3084910: Insert tabledrag changed mark after the drag handle, and not after the last item in the cell. Fortunately, this is easy & non-disruptive to do in Claro
  • Another core issue that has BC concerns is #3083044: Prevent line breaks in draggable (first) table cells. This is fixed in Claro. This issue should refactor that fix so it's implementation does not require overriding significant portions of core's Tabledrag. The symptoms of this bug are far more likely to occur in Claro due to larger margins and font sizes, so it's necessary to keep this fix even though it's otherwise present in core. The markup should be added after core's tabledrag initialization. There will also need to be event handlers that rebuild this markup after events that change it back to the not-fixed version.

    Here's a comment from the source code that explains the markup changes and their reason for being there.

    * This addresses an issue specific to item labels that are long enough
      * to be wrapped to a new line. Without this fix, a new line may start
      * at the beginning of the table row, instead of the expected behavior of
      * starting at the x axis of the first line.* Addressing this issue requires changing the structure of a tabledrag
      * cell's first row.
      * @example
      *   <!-- Default tabledrag structure, which has the wrapping problem. -->
      *   <tr class="draggable">
      *     <td>
      *       <!--
      *         Indentations are next to each other because they are styled as
      *         `float: left;`
      *       -->
      *       <div class="indentation"></div>
      *       <div class="indentation"></div>
      *       <a class="tabledrag-handle"></a>
      *       <!-- If the text in this link wraps enough times that the element
      *         is taller than the floated elements preceding it, some lines
      *         will wrap to the beginning of the row instead of aligning with
      *         the beginning of the link text.
      *       -->
      *       <a class="menu-item__link">A longer label that may require wrapping</a>
      *     </td>
      *     <!-- etc. -->
      *   </tr>
      * @example
      * <!-- Claro tabledrag structure, this fixes the wrapping problem. -->
      *   <tr class="draggable">
      *     <td class="tabledrag-cell">
      *       <div class="tabledrag-cell-content">
      *          <!-- Indentations are next to each other because
      *            .table-drag-cell-content is styled as `display: table-row;`
      *            and .table-drag-cell-content > * is styled as
      *            `display: table-cell;`
      *          -->
      *         <div class="indentation"></div>
      *         <div class="indentation"></div>
      *         <a class="tabledrag-handle"></a>
      *         <div class="tabledrag-cell-content__item">
      *           <!-- Placing the link inside a div styled as
      *             `display: table-cell;` allows the text to wrap within
      *             the boundaries of the "cell".
      *           -->
      *           <a class="menu-item__link">A longer label that may require wrapping</a>
      *         </div>
      *      </div>
      *    </td>
      *    <!-- additional <td> -->
      *   </tr>
      *

Proposed resolution

Replace the currently all-encompassing Claro Tabledrag JS with a version with a much smaller footprint, using the approach described in the above problem/motivation section.

Expand Claro's tabledrag test coverage to ensure issues like #3092181: Nested Paragraphs create multiple drag handles don't sneak through.

CommentFileSizeAuthor
#41 interdiff_35-40.txt2.72 KBbnjmnm
#41 3083051-40.patch131.3 KBbnjmnm
#35 3083051-35.patch131.16 KBbnjmnm
#35 interdiff_29-35.txt5.99 KBbnjmnm
#33 tabledragWithPatch.png250.46 KBbnjmnm
#29 Screen Shot 2020-11-11 at 6.31.35 AM.png81.6 KBbnjmnm
#29 interdiff__21-29.txt4.82 KBbnjmnm
#29 3083051--29-REROLL-PLUS.patch129.32 KBbnjmnm
#28 3083051-28.patch127.1 KBanushrikumari
#24 Screenshot 2020-11-05 at 14.21.55.png70.26 KBJeroenT
#21 interdiff_19-21.txt21.35 KBbnjmnm
#21 3083051-21.patch129.42 KBbnjmnm
#19 interdiff_17-19.txt3.29 KBbnjmnm
#19 3083051-19.patch108.62 KBbnjmnm
#18 Screenshot 2020-09-29 at 17.37.57.png3.87 KBlauriii
#18 Screenshot 2020-09-29 at 17.37.06.png29.51 KBlauriii
#17 interdiff_15-17.txt949 bytesbnjmnm
#17 3083051-17.patch106.57 KBbnjmnm
#15 3083051-15.patch106.01 KBbnjmnm
#15 interdiff_13-15.txt1019 bytesbnjmnm
#13 3083051-13.patch105.01 KBbnjmnm
#10 3083051-10.patch210.51 KBbnjmnm
#9 3083051-9.patch104.58 KBbnjmnm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Project: Claro » Drupal core
Version: 8.x-1.x-dev » 8.9.x-dev
Component: Code » Claro theme

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.

nod_’s picture

Issue tags: +JavaScript
lauriii’s picture

Issue summary: View changes
lauriii’s picture

Issue summary: View changes
Status: Postponed » Active
Related issues:

I think we can de-scope #3083039: Allow tabledrag to be disabled from the Claro roadmap since it's a new core feature which is not specific to Claro.

In the scope of this issue, we could probably override Drupal.tableDrag.prototype.row.prototype.markChanged instead of solving #3084910: Insert tabledrag changed mark after the drag handle, and not after the last item in the cell. Removing it from the dependencies and unpostponing this.

It seems like Claro also adds some additional wrappers inside tabledrag cells. We might be able to adjust some styles to not depend on those. However, if that doesn't seem feasible, we should open additional issues for adding APIs that would allow Claro to add those wrappers.

lauriii’s picture

Related issues:
bnjmnm’s picture

Work in progress. This strips out evertying other than the needed overrides.
Still need to address positioning issues in IE11 and confirm there aren't any styles referencing selectors no longer in use.

bnjmnm’s picture

Another work in progress. This patch includes #3083256: Create smaller variations for form elements, which seems (?) pretty close to completion.

Currently working on getting it to consistently look good in Paragraphs and nested tables with/without table weights being visible. This works fine with Claro's current implementation, but it needs to work without the wrapper div being added, otherwise there's a risk of breaking BC.

thamas’s picture

lauriii’s picture

Discussed with @ckrina, @saschaeggi and @Gábor Hojtsy and we agreed that we can move forward on this even before #3083044: Prevent line breaks in draggable (first) table cells has been resolved.

bnjmnm’s picture

Status: Active » Needs review
FileSize
105.01 KB

Interdiff wouldn't be particularly helpful as the scope and code it's riffing on has changed since the prior patches were posted.

This removes most of Claro's tabledrag code. The theme functions are still there, and a behavior was added to maintain the tabledrag wrapping fix that was previously in an override of the very large makeDraggable function. I did some tests to see if this approach was susceptible to a race condition an it doesn't appear to be, but feedback on that would be great.

Status: Needs review » Needs work

The last submitted patch, 13: 3083051-13.patch, failed testing. View results

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
1019 bytes
106.01 KB

\Drupal\FunctionalJavascriptTests\Theme\ClaroEntityDisplayTest::testEntityForm needed to be updated since toggle weights was changed from a link to button (which happens to match core and is the correct element for the functionality).

Status: Needs review » Needs work

The last submitted patch, 15: 3083051-15.patch, failed testing. View results

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
106.57 KB
949 bytes

There was another "show weights" toggle that needed to be changed to a button.

lauriii’s picture

Issue summary: View changes
Status: Needs review » Needs work
FileSize
29.51 KB
3.87 KB

Did a bit of manual testing with #17:


  1. For some reason, the tree is not rendered correctly after the third item.

  2. Focus ring is rendered behind the table header.
bnjmnm’s picture

Status: Needs work » Needs review
FileSize
108.62 KB
3.29 KB

Addresses #18

lauriii’s picture

Status: Needs review » Needs work

Discussed with @bnjmnm and we thought it would be good idea to bring test coverage from #3092181: Nested Paragraphs create multiple drag handles here so that they are not lost.

bnjmnm’s picture

This adds the test coverage from #3092181: Nested Paragraphs create multiple drag handles , which confirms that the errors reported in that issue happen to be fixed here as well.

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.

JeroenT’s picture

I haven't reviewed the code in depth, but I'm using patch #22 on Drupal 9.0.7 with nested paragraphs and it's working fine for me!

JeroenT’s picture

Not sure if this is related to this patch, but I noticed a weird dash on every record of e.g. Form display:

Pasqualle’s picture

Status: Needs review » Needs work

needs reroll

anmolgoyal74’s picture

Assigned: Unassigned » anmolgoyal74
anmolgoyal74’s picture

Assigned: anmolgoyal74 » Unassigned
anushrikumari’s picture

Status: Needs work » Needs review
FileSize
127.1 KB

Rerolled patch #21 for 9.2.x

bnjmnm’s picture

Rerolled and fixed a few small things.

I'm not seeing the dashes reported in #24, but if there are specific steps to reproduce I'll check those against what I did to get this screenshot.

Status: Needs review » Needs work

The last submitted patch, 29: 3083051--29-REROLL-PLUS.patch, failed testing. View results

bnjmnm’s picture

Status: Needs work » Needs review

Test failure was in an unrelated test known to intermittently fail.

ac’s picture

The patch in #21 introduces the issue in #24. You can see it by navigating to a menu page like /admin/structure/menu/manage/main when using Claro as admin theme.

With stock core 9.0.9, the markup is:
<a href="#" class="tabledrag-handle js-tabledrag-handle" title="Drag to re-order"></a>

After the patch it is:
<a href="#" class="tabledrag-handle" title="Drag to re-order"><div class="handle">&nbsp;</div></a>

It is the extra <div class="handle">&nbsp;</div> that causes the issue seen in #24

bnjmnm’s picture

FileSize
250.46 KB

#32 identified where the point of confusion is! This was incredibly helpful. It mentions "With stock core 9.0.9, the markup is:"

This patch builds on changes added in 9.1. It makes sense it wouldn't work right on 9.0. Patches should be tested against the version specified in the "Version" field of the issue metadata. Much of the time it's possible to get away with reviewing patches on earlier versions. However, it won't work with issues such as these that build on changes that won't be added until the next release. Since Drupal 9.1 is now in prerelease, the current dev branch is 9.2. Test against that and let me know if it's working!

nod_’s picture

Status: Needs review » Needs work

This is looking very good :) just need some clarifications, might be a good idea to put a sample html structure of what's the end result of the different functions additionnaly to the comment explaining it in english, might be faster to understand for some (like me :p) like the fact that we want the drag handle inside .tabledrag-cell-content all the time.

  1. +++ b/core/themes/claro/js/tabledrag.es6.js
    @@ -1,1704 +1,72 @@
    +          .first()
    ...
    +          .first()
    ...
    +          .first()
    

    I'd prefer that we replace first() with eq(0), we should limit the use of jquery "helpers".

  2. +++ b/core/themes/claro/js/tabledrag.es6.js
    @@ -1,1704 +1,72 @@
    +        const $targetElem = $firstCell.find('.js-tabledrag-cell-content').length
    +          ? $firstCell.find('.js-tabledrag-cell-content')
    +          : $firstCell.addClass('js-tabledrag-cell-content');
    

    not sure why we need the ternary. wrapInner $targetElem is going to be the td in all case and we just added an element with this class in there. for non-draggable rows this function will not be called so I don't see how we'll be in a situation where we do the addClass.

  3. +++ b/core/themes/claro/js/tabledrag.es6.js
    @@ -1,1704 +1,72 @@
    +          .detach()
    +          .prependTo($targetElem);
    ...
    +          .detach()
    +          .prependTo($targetElem);
    

    Not sure we need the detach, we're not holding on to the element waiting for something it's added back to the DOM straight away, is it for safety?

  4. +++ b/core/themes/claro/js/tabledrag.es6.js
    @@ -1713,27 +81,26 @@
    +          $indentToMove.detach().prependTo($cellContent);
    

    Same thing for the detach, does it messes thing up if it's not detached first?

It works and I find the same bugs we already have with the non-claro version, so that's good :)

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
5.99 KB
131.16 KB

This hopefully takes care of #34

The detach() calls weren't necessary, that was completely due to mixing this up with another issue worked on the same day 🙂

nod_’s picture

Status: Needs review » Reviewed & tested by the community

We have tests, things work as well as before and there is doc explaining why we need the js for claro.

+++ b/core/themes/claro/js/tabledrag.es6.js
@@ -1,1704 +1,115 @@
+        // Move handle into the '.js-tabledrag-cell-content' target.
+        $targetElem
+          .eq(0)
+          .find('> .tabledrag-cell-content__item > .js-tabledrag-handle')
+          .prependTo($targetElem);
...
+        // Move indentations into the '.js-tabledrag-cell-content' target.
+        $targetElem
+          .eq(0)
+          .find('> .tabledrag-cell-content__item >.js-indentation')
+          .prependTo($targetElem);

It's a detail, we can do a single call to find with the two selectors, that would do the same and not duplicate the code. But it works like this, no problem.

catch’s picture

Issue could use a title change and issue summary update.

bnjmnm’s picture

Title: Remove tabledrag.js replacement when core issues are resolved » Refactor tabledrag when core issues are resolved
Issue summary: View changes
Issue tags: -Needs issue summary update
Related issues: +#3083044: Prevent line breaks in draggable (first) table cells
catch’s picture

lauriii’s picture

@catch if both of those issues landed, we could remove all of the remaining overrides except the theme function overrides.

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
131.3 KB
2.72 KB

RE #39

So assuming #3084910: Insert tabledrag changed mark after the drag handle, and not after the last item in the cell and #3083044: Prevent line breaks in draggable (first) table cells eventually land in core, would we remove the remaining overrides then?

Good call, I added @todo items for those. I'd overlooked doing that as BC concerns make those issues very unlikely to happen, but it could happen in 10 or beyond.

I also consolidated the find() call based on #36

Switching back to NR for these changes, so hopefully it's quick for someone to jump in and re-review so this can be available for Claro+Paragraphs users dealing with multiple drag handles.

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

The interdiff looks good to me.

  • lauriii committed a373aa3 on 9.2.x
    Issue #3083051 by bnjmnm, anushrikumari, lauriii, JeroenT, nod_, ac,...

lauriii credited alexpott.

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

I credited @alexpott for peer-reviewing this on Slack.

Committed a373aa3 and pushed to 9.2.x. Thanks!

Not backporting to 9.1.x because the patch requires a cache clear.

lauriii credited Dakwamine.

lauriii credited elgandoz.

lauriii credited gaards.

lauriii credited ipwa.

lauriii credited jwilson3.

lauriii credited kualee.

lauriii credited msuthars.

lauriii credited pavnish.

lauriii credited slasher13.

lauriii’s picture

lauriii’s picture

ipwa’s picture

Sorry for commenting on a Fixed issue, but I wanted to know if this was going to get backported to Drupal 8? At the moment Paragraphs is pretty much unusable with Claro in D8 unless you use a patch from #3092181: Nested Paragraphs create multiple drag handles .

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Lukas von Blarer’s picture

Does anyone have a patch that applies against latest 9.1.x?

bnjmnm’s picture

#62

this was going to get backported to Drupal 8

No
#64

Does anyone have a patch that applies against latest 9.1.x?

Adding this to versions earlier than 9.2 isn't feasible as it depends on several other changes only present in 9.2. There is a different issue that has patches that have worked for earlier versions: #3092181: Nested Paragraphs create multiple drag handles . I'm unsure if these patches still work, but they don't depend on the changes specific to 9.2 as they make changes to the buggy code instead of this issues approach: removing the buggy code altogether and letting core take care of it.

Lukas von Blarer’s picture