Bugfix/15245 set focus within amends #15252
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
If you open an element in a slideout (e.g. an entry), we programmatically set the focus on the first field or the container (if no focusable elements can be found). That works well most of the time, but in some edge cases, it would be better to set the focus on the container despite being able to find at least one focusable element.
Example 1
You have an element without a title field (for example, it’s hidden), and the first focusable element is a dropdown.
In this case, the selectize field will be focused on and activated, causing the
select_on_focus
plugin to kick in and mark the field as modified. It also triggers the form observer errors.Example 2
You have an element that doesn’t have a title field (for example, it’s hidden), and the first visible field is a CKEditor field, followed by a dropdown field, followed by a plain text field.
The CKEditor field will not be considered focusable in time for
Garnish.setFocusWithin()
to find it; we need to exclude the selectized field from being the first focusable element. This means the focus will be set on the plain text field, which seems odd and could be confusing.Solution:
I have excluded selectized field from being the first focusable element.
If the first focusable element container is different from the first visible field on the page, set the focus on the container.
Related issues
#15245