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.
- #3077938: Add a new Drupal.theme JavaScript function for tabledrag handle to allow themes customize the handle's markup
- #197641: Drag and drop is not RTL aware
- #3084916: Add a new Drupal.theme JavaScript function for theming the the show/hide row weight toggle and its wrapper in draggable tables
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.
Comment | File | Size | Author |
---|---|---|---|
#41 | interdiff_35-40.txt | 2.72 KB | bnjmnm |
#41 | 3083051-40.patch | 131.3 KB | bnjmnm |
#35 | 3083051-35.patch | 131.16 KB | bnjmnm |
#35 | interdiff_29-35.txt | 5.99 KB | bnjmnm |
#33 | tabledragWithPatch.png | 250.46 KB | bnjmnm |
Comments
Comment #2
huzookaComment #3
huzookaComment #5
nod_Comment #6
lauriiiComment #7
lauriiiI 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.
Comment #8
lauriiiComment #9
bnjmnmWork 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.
Comment #10
bnjmnmAnother 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.
Comment #11
thamasComment #12
lauriiiDiscussed 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.
Comment #13
bnjmnmInterdiff 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.Comment #15
bnjmnm\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).Comment #17
bnjmnmThere was another "show weights" toggle that needed to be changed to a button.
Comment #18
lauriiiDid a bit of manual testing with #17:
For some reason, the tree is not rendered correctly after the third item.
Focus ring is rendered behind the table header.
Comment #19
bnjmnmAddresses #18
Comment #20
lauriiiDiscussed 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.
Comment #21
bnjmnmThis 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.
Comment #23
JeroenTI 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!
Comment #24
JeroenTNot sure if this is related to this patch, but I noticed a weird dash on every record of e.g. Form display:
Comment #25
Pasqualleneeds reroll
Comment #26
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #27
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #28
anushrikumari CreditAttribution: anushrikumari at OpenSense Labs commentedRerolled patch #21 for 9.2.x
Comment #29
bnjmnmRerolled 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.
Comment #31
bnjmnmTest failure was in an unrelated test known to intermittently fail.
Comment #32
acThe 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"> </div></a>
It is the extra
<div class="handle"> </div>
that causes the issue seen in #24Comment #33
bnjmnm#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!
Comment #34
nod_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.I'd prefer that we replace
first()
witheq(0)
, we should limit the use of jquery "helpers".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.
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?
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 :)
Comment #35
bnjmnmThis 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 🙂Comment #36
nod_We have tests, things work as well as before and there is doc explaining why we need the js for claro.
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.
Comment #37
catchIssue could use a title change and issue summary update.
Comment #38
bnjmnmComment #39
catchSo 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?
Comment #40
lauriii@catch if both of those issues landed, we could remove all of the remaining overrides except the theme function overrides.
Comment #41
bnjmnmRE #39
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 #36Switching 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.
Comment #42
chr.fritschThe interdiff looks good to me.
Comment #45
lauriiiI 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.
Comment #58
lauriiiCrediting folks from #3092181: Nested Paragraphs create multiple drag handles .
Comment #61
lauriiiComment #62
ipwa CreditAttribution: ipwa at manifesto commentedSorry 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 .
Comment #64
Lukas von BlarerDoes anyone have a patch that applies against latest 9.1.x?
Comment #65
bnjmnm#62
No
#64
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.
Comment #66
Lukas von BlarerSorry, I didn't test the latest patch in #3092181: Nested Paragraphs create multiple drag handles . This works for me:
https://www.drupal.org/project/drupal/issues/3092181#comment-13931509