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

Disable initialFocus and setReturnFocus in focusTrap for screen #49240

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions src/components/FocusTrap/FocusTrapForScreen/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import sharedTrapStack from '@components/FocusTrap/sharedTrapStack';
import TOP_TAB_SCREENS from '@components/FocusTrap/TOP_TAB_SCREENS';
import WIDE_LAYOUT_INACTIVE_SCREENS from '@components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import CONST from '@src/CONST';
import type FocusTrapProps from './FocusTrapProps';

Expand Down Expand Up @@ -42,27 +41,15 @@ function FocusTrapForScreen({children, focusTrapSettings}: FocusTrapProps) {
paused={!isFocused}
containerElements={focusTrapSettings?.containerElements?.length ? focusTrapSettings.containerElements : undefined}
focusTrapOptions={{
onActivate: () => {
(document?.activeElement as HTMLElement)?.blur();
},
trapStack: sharedTrapStack,
allowOutsideClick: true,
fallbackFocus: document.body,
delayInitialFocus: CONST.ANIMATED_TRANSITION,
initialFocus: (focusTrapContainers) => {
if (!canFocusInputOnScreenFocus()) {
return false;
}

const isFocusedElementInsideContainer = focusTrapContainers?.some((container) => container.contains(document.activeElement));
if (isFocusedElementInsideContainer) {
return false;
}
return undefined;
},
setReturnFocus: (element) => {
if (document.activeElement && document.activeElement !== document.body) {
return false;
}
return element;
},
initialFocus: false,
setReturnFocus: false,
...(focusTrapSettings?.focusTrapOptions ?? {}),
}}
>
Expand Down
Loading