Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/15245 set focus within amends #15252

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

i-just
Copy link
Contributor

@i-just i-just commented Jun 26, 2024

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

@brandonkelly brandonkelly merged commit a1f0b5b into 4.x Jun 27, 2024
@brandonkelly brandonkelly deleted the bugfix/15245-set-focus-within-amends branch June 27, 2024 03:33
brianjhanson added a commit that referenced this pull request Jun 27, 2024
Checks if the toggle is visible (which indicates that we're in a mobile-ish view) before adjusting the position of the sidebar container.

We could use a media query or something here, but this felt a little less error prone for now.

Fixes #15252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants