Ajax replace does not refocus element if inside a dialog

Created on 12 December 2018, about 6 years ago
Updated 23 November 2023, about 1 year ago

Problem/Motivation

Drupal.Ajax.success attempts to set focus to the element that triggered the ajax request.

You can stop by adding the attribute data-disable-refocus to the element if another InvokeCommand is returned that sets focus.

This functionality is not actually tested anywhere and it does not work if the element is inside a dialog.
In #2995689: Allow reordering blocks without a pointer device it would be great if this worked because we are using an ajax element in dialog.

Proposed resolution

In the AJAX success handler, after the $(target).trigger('focus'); check to see if target is in a dialog.

If it is in a dialog AND that dialog does not have a dedicated focus listener (we don't want to override a deliberately added focus listener), add a temporary focus listener to the dialog for when it receives focus due to autofocus. The focus listener callback will reroute focus back to target where it was intended to go.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.2

Component
Ajax 

Last updated 1 day ago

Created by

🇺🇸United States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024