fix(overlays): focus is returned to last focus element when focusing toast #28950
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.
Issue number: resolves #28261
What is the current behavior?
When moving focus from a focus-trapped overlay to a toast, focus is moved back to the overlay. This is the correct behavior as focus should never leave a focus-trapped overlay (unless the overlay is dismissed or focus is moved to a new top-most overlay). However, the way we return focus is a bit unexpected because it always returns focus to the last focusable element in the overlay.
This means that if you were focused on the first focusable element, presented the toast, and then focused the toast, focus might not be moved back to that first focusable element. In the case of the linked issue, this was causing an unexpected scroll so that the last focused element could be in view.
What is the new behavior?
ion-toast
(as it is the only overlay that is not focus trapped) that ensures that focus is moved back to the last focus element.Does this introduce a breaking change?
Other information
Dev build:
7.7.1-dev.11707253408.186eea70
Note: We don't recommend this pattern in general because it would be impossible for a screen reader user to focus the toast. However, we can at least improve the experience for developers who continue to implement this pattern by returning focus in a more predictable manner.
Docs: ionic-team/ionic-docs#3432
Testing:
Reviewers should manually test the following behaviors: