-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add focus trap to the RHP (v2) #27670
Merged
roryabraham
merged 33 commits into
Expensify:main
from
software-mansion-labs:@kosmydel/add-focus-trap-2
Nov 20, 2023
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
256a839
Revert "Revert "Add focus trap to the RHP""
kosmydel 8f1c892
fix initial state in the TwoFactorAuthSteps
kosmydel b8ca73d
fix focus issue
kosmydel 550d385
Refactor
kosmydel 857f999
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 27bbf8b
Merge branch 'expensify-main' into @kosmydel/add-focus-trap-2
kosmydel 9a06735
refactor calculateCurrentStep
kosmydel ad9911a
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 76e9195
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel be7a368
use useIsFocused hook
kosmydel be394f0
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 9fb1ff7
enable focus trap in the ConfirmModal
kosmydel d9f48e2
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 2a62369
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 9747b20
prettier
kosmydel 18a0aea
refactor
kosmydel 6890531
refactor TwoFactorAuthSteps
kosmydel f0ec2ca
fix confirmation modal issue
kosmydel 3f51f98
fix
kosmydel 5462980
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 49c8699
use tabIndex property
kosmydel 16b8cb2
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 7135f06
prettier
kosmydel 528bd09
Merge branch 'Expensify:main' into @kosmydel/add-focus-trap-2
kosmydel 317b982
Merge branch 'Expensify:main' into @kosmydel/add-focus-trap-2
kosmydel b78323a
Refactor FocusTrapView component
kosmydel 0636be5
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel d000814
fix types
kosmydel 3a1cf2e
new ref type
kosmydel 23c1eb6
Merge branch 'main' into @kosmydel/add-focus-trap-2
kosmydel 4a12485
fix attachment focus trap issue
kosmydel 2376853
address review
kosmydel 25c5125
fix split details and details
kosmydel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* The FocusTrap is only used on web and desktop | ||
*/ | ||
import FocusTrapViewProps from './types'; | ||
|
||
function FocusTrapView({children}: FocusTrapViewProps) { | ||
return children; | ||
} | ||
|
||
FocusTrapView.displayName = 'FocusTrapView'; | ||
|
||
export default FocusTrapView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* The FocusTrap is only used on web and desktop | ||
*/ | ||
import FocusTrap from 'focus-trap-react'; | ||
import React, {useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import viewRef from '@src/types/utils/viewRef'; | ||
import FocusTrapViewProps from './types'; | ||
|
||
function FocusTrapView({isEnabled = true, isActive = true, shouldEnableAutoFocus = false, ...props}: FocusTrapViewProps) { | ||
/** | ||
* Focus trap always needs a focusable element. | ||
* In case that we don't have any focusable elements in the modal, | ||
* the FocusTrap will use fallback View element using this ref. | ||
*/ | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
return isEnabled ? ( | ||
<FocusTrap | ||
active={isActive} | ||
focusTrapOptions={{ | ||
initialFocus: () => (shouldEnableAutoFocus && ref.current) ?? false, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
fallbackFocus: () => ref.current!, | ||
clickOutsideDeactivates: true, | ||
}} | ||
> | ||
<View | ||
ref={viewRef(ref)} | ||
tabIndex={0} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
/> | ||
</FocusTrap> | ||
) : ( | ||
props.children | ||
); | ||
} | ||
|
||
FocusTrapView.displayName = 'FocusTrapView'; | ||
|
||
export default FocusTrapView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {ViewProps} from 'react-native'; | ||
import ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
|
||
type FocusTrapViewProps = ChildrenProps & { | ||
/** | ||
* Whether to enable the FocusTrap. | ||
* If the FocusTrap is disabled, we just pass the children through. | ||
*/ | ||
isEnabled?: boolean; | ||
|
||
/** | ||
* Whether to disable auto focus | ||
* It is used when the component inside the FocusTrap have their own auto focus logic | ||
*/ | ||
shouldEnableAutoFocus?: boolean; | ||
|
||
/** Whether the FocusTrap is active (listening for events) */ | ||
isActive?: boolean; | ||
} & ViewProps; | ||
|
||
export default FocusTrapViewProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Please use v10.2.3 to include focus-trap/focus-trap#1068