[drupalMedia] Using the Insert Media button causes the window to scroll to the bottom of the page

Created on 19 January 2024, 8 months ago
Updated 10 September 2024, 10 days ago

Problem/Motivation

On Drupal 10.2.2, when adding a Media element via the Insert Media button, once "Insert selected" is pressed, the window scrolls to the bottom of the page. This happens with any Wysiwyg using CKEditor 5 with the Insert Media button enabled.

This behavior is disruptive to content authors/editors as it interrupts the flow of adding content.

Steps to reproduce

  • Ensure you're on an Drupal 10.2.2 environment.
  • On one of the options under "Text formats and editors", add CKEditor 5 as the Text editor and ensure that the Insert Media button is available under the "Active toolbar".
  • Enable this Text format on the body or other text field of any content type.
  • Create a node of this content type, and in the above field, add a media item using the Insert Media button (I found this behavior with Images and Remote Videos but it may exist for other Media types as well).
  • After choosing an Image or other Media, after clicking "Insert selected", you should see the window scroll to the bottom of the page.

Proposed resolution

Rather than scrolling to the bottom of the page, the window should stay in place after the Media is inserted in order to allow for content authors to continue the flow of adding content.

When a Table is inserted, for instance, the window stays in place, so the Insert Media button should function the same.

Observation

At first I thought this was a Claro issue, but when I switched to a different Admin theme (in this case switching it to the custom frontend theme), the issue still existed.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
CKEditor 5 

Last updated about 6 hours ago

Created by

🇺🇸United States morganlyndel

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

  • JavaScript

    Affects the content, performance, or handling of Javascript.

  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

  • Needs accessibility review

    Used to alert the accessibility topic maintainer(s) that an issue significantly affects (or has the potential to affect) the accessibility of Drupal, and their signoff is needed (see the governance policy draft for more information). Useful links: Drupal's accessibility standards, the Drupal Core accessibility gate.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @morganlyndel
  • 🇺🇸United States cilefen
  • Status changed to Postponed: needs info 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    I cannot reproduce this. In which browser is this happening?

  • 🇮🇳India gouthamraon

    We are also facing the same issue.

    After upgrading site to 10.2.2, we are seeing this issue.

    @wim-leers : I tried this in Chrome and Firefox, both i'm seeing this issue.

  • Status changed to Needs review 7 months ago
  • 🇮🇳India gouthamraon

    Created a patch for the issue mentioned, please review.

  • Status changed to Needs work 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Thank you very much for pushing this forward, @gouthamraon! 😊

    AFAICT this is a duplicate of 🐛 CKEditor 5: scroll jump after dialog close Active . But this now has a patch (thanks @gouthamraon!). But that issue is more general: it reports a similar problem with all dialogs. (The GIF there demonstrates this problem using the https://www.drupal.org/project/ckeditor_templates contrib module.)

    I think the patch in #5 also has an impact when using the media library dialog in non-CKEditor 5 contexts 😅 So I think right now this is fixing one problem and introducing another.

    Or … is this actually fixing a bug elsewhere in core too?

    IOW: we need to test the #5 patch when using a media field.

    Conclusion:

    1. either this should be marked as a duplicate of 🐛 CKEditor 5: scroll jump after dialog close Active , because we should not change the media library dialog
    2. or this is the correct fix, and it improves the media library dialog's accessibility in non-CKEditor 5 contexts too, and 🐛 CKEditor 5: scroll jump after dialog close Active is really just reporting a bug in the ckeditor_templates module

    Manual testing will tell! 😊

  • 🇮🇳India gouthamraon

    @wim-leers :I have verified the #5 patch with the media field and it's working fine.

  • 🇺🇦Ukraine edwardsay

    Unfortunately, patch #5 does not work for me. It affects the "Insert selected" button, but not the close X button of the dialog itself. So when I close dialog the page jumps to the top of the CKE5 editor.

    The JS solution from https://www.drupal.org/project/drupal/issues/3410598 🐛 CKEditor 5: scroll jump after dialog close Active works for drupalMedia CKE plugin too, though.

  • 🇺🇦Ukraine vselivanov Kyiv, Ukraine

    I had exactly the same issue with scroll and patch #5 fixed it.
    Thank you, @gouthamraon!

  • 🇺🇸United States anand.panure

    We are facing the same issue with drupal 10.2.3 and CKEditor5, the focus moves to the bottom of the page after adding a media inside the CkEditor and also attaching an image from the Imagery tab for my banner.

    The patch #5, is helpful but it shifts your focus to the "Insert Media" button. So, if it's a large page and you use sticky toolbar of CKEditor, the focus moves to the toolbar (which you can say is to the top of the page.)

    Thanks,
    Anand Panure

  • 🇨🇦Canada francismak

    Hi,

    We are having the same issue, and the patch #5 is working, thx @gouthamraon.

    The "jumping/scrolling" was caused by trying to get the parent element of the dialog.
    L1126 of core/misc/ajax.js

    Original issue:
    Focus state bug on text field AJAX calls 🐛 Focus state bug on text field AJAX calls Fixed

    It introduced a new thing "preCommandsFocusedElementSelector". So if refocus back to "Insert Media" button is a problem as mentioned in #11, maybe able to make sure of this new command.

    Ideally, it should focus the newly created media inside the CKEditor. However, the element doesn't exist before clicking the button.
    And there is nothing to focus if user click 'x' to close the dialog in 3410598 🐛 CKEditor 5: scroll jump after dialog close Active

    Instead of focus, I wonder if there is a way to "do nothing".

  • 🇫🇷France kumkum29

    As @anand.panure says, we are facing the same issue on D9.5.11 + ckeditor5. I need to update Drupal to 10.2, but I need to resolve this issue before that.

    Is there a quick fix to resolve this problem and keep the position of the inserted media ?

    The mentionned fix in #5 already exists in the media_library of core (in D9.5.11).

    Thanks.

Production build 0.71.5 2024