Problem/Motivation
Layout builder's interface is always jumping (scrolling) to the top of the page after removing a section or a block.
This is especially annoying when dealing with a page with lots of contents as we need to re-scroll back to where we were each time.
Steps to reproduce:
1. Install default site profile. Theme Oliviero will be configured on Front.
2. Enable module "Layout Builder"
3. On page "Block Layout" /admin/structure/block disable blocks "Search form (narrow)" and "Search form (wide)"
4. Enable Layout Builder for a content type, for example Basic Page "/admin/structure/types/manage/page/display"
5. Go to Layout Builder configuration for a Content type /admin/structure/types/manage/page/display/default/layout
6. Try to add a new Section/Block
7. Remove a Section
8. After submit, the page focuses on a "Save" button which is on top.
The issue is related to Drupal AJAX behavior on success defined in core/misc/ajax.js, see $(target).trigger('focus');.
The AJAX system automatically moves focus to the first tabbable element after closing a dialog, sometimes scrolling to a page top.
Proposed resolution
Disable refocus after a dialog close for Layout Rebuild forms (Remove Section/Block).
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 3152561-lb_jumps_top-16.patch | 1.44 KB | lexbritvin |
Issue fork drupal-3152561
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:
- 3152561-layout-builder-jumps
changes, plain diff MR !4719
Comments
Comment #2
tim.plunkettOh wow, that is very annoying indeed.
It looks like this code was added in #2994909: Highlight active element while working with dialogs in Layout Builder.
It makes sense for the cases where something is being added or configured. But in the case of removal, I agree it should stay put.
Please try this patch (don't worry about the 9.1 vs 8.9, it should be the same for both)
Comment #4
EricRondo commentedSorry this is not working for me, same behavior (applied patch, flushed cache, added block, then removed : back to top :-))
Comment #7
twiik commentedNot working for me either. Testing on 8.9.15.
I also tried removing all the "scroll"-code I could find in the layout builder javascript files, but that made no difference to this behavior.
The only way I was able to stop it from happening was by removing the AjaxResponse in the LayoutRebuildTrait, but then nothing happens obviously, but just creating a new AjaxResponse in rebuildLayout function with none of the other code cause it to happen. Like it still happens if my LayoutRebuildTrait looks like this:
Maybe you can alter the AjaxResponse and something else is altering in some behavior which causes the browser to scroll to the top of the page if the response is there? I dunno, I'm not very knowledgable about how anything fits together in Drupal, especially not if involves javascript. :p
I'm changing the priority to "Major" as I feel this is currently a huge UX issue, albeit one which hopefully has a very simple fix. I'm just not able to find it.
Comment #8
james hawthorn-byng commentedJust tested this patch on 9.1.10 and also doesn't work :(
I agree that this is quite a major UX issue especially as pages can get quite long.
Comment #11
pyrello commentedI just tested this against 9.3.x and the patch still applies, but the behavior that it causes does not seem correct. What I would expect to see is that the page does not scroll/jump to the top before scrolling/jumping to the location of the block or section being removed. Instead what the patch does is preserves the initial jump to the top, but then the jump back to the element being removed never happens.
Comment #16
lexbritvin commentedAfter investigation, the issue doesn't always reproduce. I added steps to reproduce to the issue summary. And updated the proposed resolution block.
I tested the solution on 9, 10 and 11-dev.
I opened a MR with the proposed solution. Likewise, I also attach a patch for history and usage in a project.
I'm not sure if we can add tests for this change.
Comment #17
smustgrave commentedVerified the issue following the steps in the IS
Patch #16 did solve the issue.
Lowering to normal though as annoying as this is doesn't seem to break anything.
Thanks!
Comment #20
larowlanI agree this would be difficult to test, and it can be easily manually tested. On the basis of our new proposed heuristics I think this can go in without tests.
I checked in gitlab for any other classes in contrib that extend this class that may not want this behaviour but could not find any.
Committed to 11.x and backported to 10.1.x