-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Update focus trap #55285
Merged
mountiny
merged 5 commits into
Expensify:main
from
bernhardoj:fix/54335-update-focus-trap
Jan 23, 2025
Merged
Update focus trap #55285
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
diff --git a/node_modules/focus-trap/dist/focus-trap.esm.js b/node_modules/focus-trap/dist/focus-trap.esm.js | ||
index 46c8d52..6919e00 100644 | ||
--- a/node_modules/focus-trap/dist/focus-trap.esm.js | ||
+++ b/node_modules/focus-trap/dist/focus-trap.esm.js | ||
@@ -118,8 +118,8 @@ var isKeyForward = function isKeyForward(e) { | ||
var isKeyBackward = function isKeyBackward(e) { | ||
return isTabEvent(e) && e.shiftKey; | ||
}; | ||
-var delay = function delay(fn) { | ||
- return setTimeout(fn, 0); | ||
+var delay = function delay(fn, delayTime = 0) { | ||
+ return setTimeout(() => setTimeout(fn, delayTime), 0); | ||
}; | ||
|
||
/** | ||
@@ -771,7 +771,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) { | ||
// that caused the focus trap activation. | ||
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () { | ||
_tryFocus(getInitialFocusNode()); | ||
- }) : _tryFocus(getInitialFocusNode()); | ||
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined) : _tryFocus(getInitialFocusNode()); | ||
doc.addEventListener('focusin', checkFocusIn, true); | ||
doc.addEventListener('mousedown', checkPointerDown, { | ||
capture: true, | ||
@@ -909,7 +909,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) { | ||
_tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)); | ||
} | ||
onPostDeactivate === null || onPostDeactivate === undefined || onPostDeactivate(); | ||
- }); | ||
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined); | ||
}; | ||
if (returnFocus && checkCanReturnFocus) { | ||
checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation); | ||
diff --git a/node_modules/focus-trap/index.d.ts b/node_modules/focus-trap/index.d.ts | ||
index a7fb3be..6e85116 100644 | ||
--- a/node_modules/focus-trap/index.d.ts | ||
+++ b/node_modules/focus-trap/index.d.ts | ||
@@ -187,7 +187,7 @@ declare module 'focus-trap' { | ||
* This prevents elements within the focusable element from capturing | ||
* the event that triggered the focus trap activation. | ||
*/ | ||
- delayInitialFocus?: boolean; | ||
+ delayInitialFocus?: boolean | number; | ||
/** | ||
* Default: `window.document`. Document where the focus trap will be active. | ||
* This allows to use FocusTrap in an iFrame context. | ||
diff --git a/node_modules/focus-trap/index.js b/node_modules/focus-trap/index.js | ||
index 36d901c..fcbadc7 100644 | ||
--- a/node_modules/focus-trap/index.js | ||
+++ b/node_modules/focus-trap/index.js | ||
@@ -66,8 +66,8 @@ const isKeyBackward = function (e) { | ||
return isTabEvent(e) && e.shiftKey; | ||
}; | ||
|
||
-const delay = function (fn) { | ||
- return setTimeout(fn, 0); | ||
+const delay = function (fn, delayTime = 0) { | ||
+ return setTimeout(() => setTimeout(fn, delayTime), 0); | ||
}; | ||
|
||
/** | ||
@@ -832,7 +832,7 @@ const createFocusTrap = function (elements, userOptions) { | ||
state.delayInitialFocusTimer = config.delayInitialFocus | ||
? delay(function () { | ||
tryFocus(getInitialFocusNode()); | ||
- }) | ||
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined) | ||
: tryFocus(getInitialFocusNode()); | ||
|
||
doc.addEventListener('focusin', checkFocusIn, true); | ||
@@ -1006,7 +1006,7 @@ const createFocusTrap = function (elements, userOptions) { | ||
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)); | ||
} | ||
onPostDeactivate?.(); | ||
- }); | ||
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined); | ||
}; | ||
|
||
if (returnFocus && checkCanReturnFocus) { |
4 changes: 2 additions & 2 deletions
4
src/components/FocusTrap/FocusTrapForModal/FocusTrapForModalProps.ts
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
4 changes: 2 additions & 2 deletions
4
src/components/FocusTrap/FocusTrapForScreen/FocusTrapProps.ts
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import type FocusTrap from 'focus-trap-react'; | ||
import type {FocusTrapProps} from 'focus-trap-react'; | ||
|
||
type FocusTrapForScreenProps = { | ||
children: React.ReactNode; | ||
|
||
/** Overrides the focus trap settings */ | ||
focusTrapSettings?: Pick<FocusTrap.Props, 'containerElements' | 'focusTrapOptions' | 'active'>; | ||
focusTrapSettings?: Pick<FocusTrapProps, 'containerElements' | 'focusTrapOptions' | 'active'>; | ||
}; | ||
|
||
export default FocusTrapForScreenProps; |
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.
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.
Is there an upstream PR for this so we can track it to remove the patch?
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.
This patch was added in #44932. They don't have an upstream PR.