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.
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
prevent initial focus trap while has a focused element. #44932
prevent initial focus trap while has a focused element. #44932
Changes from 13 commits
a1587bb
21f134f
ecdc861
38e473d
25ab7fd
08c6f03
59496ce
dc87814
8081861
bb24cd9
1e590d4
c6e1bb6
3106ce8
bd4a935
9686926
367e62f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not return focus to the initial screen if we already have a focused element, e.g. in ReportScreen after closing RHP the Composer should remain focused
Screen.Recording.2024-07-09.at.12.17.06.AM.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@s77rt I’m still working on
setReturnFocus
. Do you mean your suggestion also checks if there’s a focused element to skipsetReturnFocus
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a component using
focus-trap-react
unmounts, it calls deactivateTrap, which triggers focusTrap.deactivate. This subsequently calls getReturnFocusNode infocus-trap
. Therefore, we can’t get the containers for the next screen because when Screen B unmounts (after navigating from Screen A to Screen B), it sets the return focus node from Screen B’s context.As a result, we can’t retrieve the containers for Screen A when Screen B unmounts. Instead, we can check if the active element is the default (document body). If it is, we can return false to ensure the focus trap does not interfere with the focus transition to Screen A. Otherwise, we keep the current focused element.
I have updated the code, and it covers the issue you mentioned above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me but let's also check if
document.activeElement
isnull
. In that case we want to return the focus as wellThis file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB