Skip to content

Commit

Permalink
Merge pull request #49240 from tsa321/blueBorderAll
Browse files Browse the repository at this point in the history
Disable initialFocus and setReturnFocus in focusTrap for screen
  • Loading branch information
srikarparsi authored Sep 24, 2024
2 parents 4ab14d6 + 62d63bf commit ae57639
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 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,30 +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));
const hasButtonWithEnterListener = !!focusTrapContainers?.some(
(container) => !!container.querySelector(`button[data-listener="${CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey}"]`),
);
if (isFocusedElementInsideContainer || hasButtonWithEnterListener) {
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

0 comments on commit ae57639

Please sign in to comment.