Skip to content

Commit

Permalink
Merge pull request #45620 from suneox/45571-prevent-inital-focus-when…
Browse files Browse the repository at this point in the history
…-screen-cannot-focus

Prevent initial focus when the screen cannot be focused.
  • Loading branch information
Julesssss authored Jul 24, 2024
2 parents 1084706 + d675642 commit 1cc3507
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/FocusTrap/FocusTrapForScreen/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 useWindowDimensions from '@hooks/useWindowDimensions';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import CONST from '@src/CONST';
import type FocusTrapProps from './FocusTrapProps';

Expand Down Expand Up @@ -42,6 +43,10 @@ function FocusTrapForScreen({children}: FocusTrapProps) {
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;
Expand Down

0 comments on commit 1cc3507

Please sign in to comment.