By bnjmnm on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.2.x
Introduced in version:
9.2.0
Issue links:
Description:
The new FocusFirstCommand is for assigning focus via an Ajax response. It is provided a selector argument, which defines the container that will have the element that will receive focus. Provided the selector exists on the page to define the container, focus is assigned based on the following:
- If at least one tabbable element is found in the container, the first in the DOM receives focus
- If no tabbable elements are found in the container, but the container itself is focusable, then the container is focused
- If none of the above conditions are true, focus remains on the triggering element.
For example:
$response = new AjaxResponse();
// The first tabbable element in #some-new-form will receive focus
$response->addCommand(new FocusFirstCommand('#some-new-form'));
Prior to the addition of this command, assigning focus via Ajax was performed via using InvokeCommand and using the :tabbable pseudoselector as an argument. This command was created because the :tabbable pseudoselector is part of the deprecated jQuery UI library, and there needed to be a way to provide this functionality that did not depend on a deprecated library.
Impacts:
Site builders, administrators, editors