Problem/Motivation

If a modal dialog is replaced with a new modal dialog, the dialog is not closed and opened but the contents are simply replaced. In this case, the focus is returned to the dialog itself, instead of the first element within the dialog. This can be tested manually using the multistep dialogs in #3386762: Use modals in field creation and field edit flow.

Steps to reproduce

Create a new field using the multistep dialog in #3386762: Use modals in field creation and field edit flow

  1. Navigate to the manage fields page (eg. /admin/structure/types/manage/article/fields)
  2. Open the multistep field creation dialog using the Create a new field button.
  3. Click on any of the field type cards to move to the next step.
  4. Go back to the previous form using the Change field type button.
  5. Observe that the focus is returned to the dialog instead of the first element within the dialog.

Proposed resolution

Move focus to the first tabbable element in the dialog when the content is replaced.
Before: Focus is returned to the dialog

After: Focus is moved to the first element within the dialog.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3397785

Command icon 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:

Comments

lauriii created an issue. See original summary.

lauriii’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Seems to have a test failure.

yash.rode made their first commit to this issue’s fork.

yash.rode’s picture

Status: Needs work » Needs review

I have tested this manually and fixed all the failing tests.

lauriii’s picture

@yash.rode can you summarize here what was the change in behavior you noticed when you updated the tests?

yash.rode’s picture

The change in tests is regarding the lines where we tried checking if the focus is on some part of modal example: media-library-content Only local images are allowed.
But now we need that focus to be on the first tabbable element present on that modal, i.e. Type one of the media library menu.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs Review Queue Initiative

Hate to do it but just to remain consistent with other tickets, can the issue summary be updated with steps to reproduce, what the proposed solution was, maybe any before/after screenshots if possible.

srishtiiee made their first commit to this issue’s fork.

srishtiiee’s picture

Issue summary: View changes
StatusFileSize
new439.16 KB
new489.37 KB
srishtiiee’s picture

Status: Needs work » Needs review
Issue tags: -Needs issue summary update
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed the fix following the steps in the issue summary. Using just my keyboard
Created a field
Selected a reference field if that matters
Tabbed and clicked change field
Focus is on the first option

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

It looks like this introduces changes to the media focus handling which is probably not desired. I think we need to try to find a way to fix the media focus handling so that we don't need to update tests related to it.

yash.rode’s picture

Status: Needs work » Needs review

addressed #14

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems feedback has been addressed.

Though wonder if a follow up is open for

I think we need to try to find a way to fix the media focus handling so that we don't need to update tests related to it.

and a todo needs to be added?

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Posted feedback in the MR

yash.rode’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Limited knowledge of the js api but appears feedback was addressed.

  • lauriii committed 762fcae9 on 11.x
    Issue #3397785 by yash.rode, srishtiiee, lauriii, smustgrave: Dialog...

  • lauriii committed 055e0831 on 10.2.x
    Issue #3397785 by yash.rode, srishtiiee, lauriii, smustgrave: Dialog...

lauriii’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 762fcae and pushed to 11.x. Also cherry-picked to 10.2.x. Thanks!

Status: Fixed » Closed (fixed)

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

mark shi’s picture

StatusFileSize
new890 bytes
new91.87 KB

This brought a new problem to me. When I removed the image or deleted the item in the dialog, the focus jumped to the top of the dialog.
I added a patch to fix this issue.
step

edwardsay’s picture

@mark-shi I had a similar issue, and your patch fixed it. I use the Layout Paragraphs module, where the paragraph form opens in a modal. Whenever I uploaded an image to the field or added a nested paragraph, the modal would scroll to the top, and the first focusable element would receive focus. This scrolling jump made content editing quite frustrating.

randy tang’s picture

Version: 10.2.x-dev » 11.2.x-dev
StatusFileSize
new972 bytes

Based on the 25th floor, this applies to floor 11.2.

arunkumark’s picture

StatusFileSize
new911 bytes

The fix is working fine. We are using the Layout paragraphs in our project. Adding or removing multivalue causes the refocus issue.

Created the patch for Drupal core 10.5.x version support.