Skip to content

Commit 107160d

Browse files
committed
refactor: remove avoidFocusTrap prop from multiple components and delete unused illustration
1 parent 0b58c21 commit 107160d

12 files changed

Lines changed: 4 additions & 36 deletions

File tree

-20.1 KB
Binary file not shown.

src/Common/Drawer/Drawer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { VisibleModal } from '../Modals/VisibleModal'
1919
import './Drawer.scss'
2020
import { DTFocusTrapType } from '@Shared/Components/DTFocusTrap'
2121

22-
export interface DrawerProps extends Pick<DTFocusTrapType, 'initialFocus' | 'avoidFocusTrap' > {
22+
export interface DrawerProps extends Pick<DTFocusTrapType, 'initialFocus'> {
2323
position: 'left' | 'right' | 'bottom' | 'top'
2424
children?: any
2525
backdrop?: boolean
@@ -45,7 +45,6 @@ export const Drawer = ({
4545
onClose,
4646
disableTransition,
4747
initialFocus = undefined,
48-
avoidFocusTrap = false,
4948
}: DrawerProps) => {
5049
const drawerRef = useRef(null)
5150
useEffect(() => {
@@ -70,7 +69,6 @@ export const Drawer = ({
7069
onEscape={onEscape}
7170
close={onClose}
7271
initialFocus={initialFocus}
73-
avoidFocusTrap={avoidFocusTrap}
7472
>
7573
<aside
7674
style={style}

src/Common/Modals/VisibleModal.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class VisibleModal extends Component<PropsWithChildren<{
2727
close?: (e?) => void
2828
onEscape?: (e?) => void
2929
initialFocus?: DTFocusTrapType['initialFocus']
30-
avoidFocusTrap?: boolean
3130
}>> {
3231
constructor(props) {
3332
super(props)
@@ -57,7 +56,6 @@ export class VisibleModal extends Component<PropsWithChildren<{
5756
onEscape={this.escFunction}
5857
onClick={this.handleBodyClick}
5958
initialFocus={this.props.initialFocus ?? undefined}
60-
avoidFocusTrap={this.props.avoidFocusTrap}
6159
>
6260
<div className={this.props.parentClassName}>
6361
<div className={`visible-modal__body ${this.props.className || ''}`}>{this.props.children}</div>

src/Shared/Components/Backdrop/Backdrop.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const Backdrop = ({
3333
deactivateFocusOnEscape = true,
3434
initialFocus,
3535
returnFocusOnDeactivate,
36-
avoidFocusTrap,
3736
}: BackdropProps) => {
3837
// STATES
3938
const [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null)
@@ -93,7 +92,6 @@ const Backdrop = ({
9392
deactivateFocusOnEscape={deactivateFocusOnEscape}
9493
initialFocus={initialFocus ?? undefined}
9594
returnFocusOnDeactivate={returnFocusOnDeactivate}
96-
avoidFocusTrap={avoidFocusTrap}
9795
>
9896
<motion.div
9997
initial={{ opacity: 0 }}

src/Shared/Components/Backdrop/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { DTFocusTrapType } from '../DTFocusTrap'
2020

2121
export interface BackdropProps extends Pick<
2222
DTFocusTrapType,
23-
'deactivateFocusOnEscape' | 'initialFocus' | 'onEscape' | 'returnFocusOnDeactivate' | 'avoidFocusTrap'
23+
'deactivateFocusOnEscape' | 'initialFocus' | 'onEscape' | 'returnFocusOnDeactivate'
2424
> {
2525
/**
2626
* The content to be rendered within the backdrop component.

src/Shared/Components/ConfirmationModal/ConfirmationModal.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const ConfirmationModalBody = ({
4646
shouldCloseOnEscape = true,
4747
isLandscapeView = false,
4848
showConfetti = false,
49-
avoidFocusTrap = false,
5049
}: ConfirmationModalBodyProps) => {
5150
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
5251

@@ -93,7 +92,6 @@ const ConfirmationModalBody = ({
9392
deactivateFocusOnEscape={shouldCloseOnEscape}
9493
// Since when custom input is present, we auto focus on input, else focus on primary button
9594
initialFocus={confirmationConfig ? false : `#${PRIMARY_BUTTON_ID}`}
96-
avoidFocusTrap={avoidFocusTrap}
9795
>
9896
<motion.div
9997
className={`${isLandscapeView ? 'w-500' : 'w-400'} confirmation-modal border__secondary flexbox-col br-8 bg__primary dc__m-auto mt-40`}

src/Shared/Components/ConfirmationModal/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export type ConfirmationModalProps<isConfig extends boolean = false> = PropsWith
104104
* @default false
105105
*/
106106
showConfetti?: boolean
107-
avoidFocusTrap?: boolean
108107
}> &
109108
ButtonConfigAndVariantType<isConfig> &
110109
(isConfig extends false

src/Shared/Components/DTFocusTrap/DTFocusTrap.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const DTFocusTrap = ({
2828
children,
2929
initialFocus = undefined,
3030
returnFocusOnDeactivate = true,
31-
avoidFocusTrap = false,
3231
}: DTFocusTrapType) => {
3332
const handleEscape = useCallback(
3433
(e?: KeyboardEvent | MouseEvent) => {
@@ -38,30 +37,16 @@ const DTFocusTrap = ({
3837
[onEscape, deactivateFocusOnEscape],
3938
)
4039

41-
// Focus escape key bind when focus trap is avoided
42-
const handleEscapeKeyBind = (e: KeyboardEvent) => {
43-
if (e.key === 'Escape') {
44-
onEscape(e)
45-
}
46-
}
47-
4840
useEffect(() => {
49-
if (avoidFocusTrap) {
50-
document.addEventListener('keydown', handleEscapeKeyBind)
51-
}
5241
preventBodyScroll(true)
5342

5443
return () => {
5544
preventBodyScroll(false)
56-
if (avoidFocusTrap) {
57-
document.removeEventListener('keydown', handleEscapeKeyBind)
58-
}
5945
}
6046
}, [])
6147

6248
return (
6349
<FocusTrap
64-
active={!avoidFocusTrap}
6550
focusTrapOptions={{
6651
escapeDeactivates: handleEscape,
6752
initialFocus,

src/Shared/Components/DTFocusTrap/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ export interface DTFocusTrapType extends Pick<FocusTrapProps['focusTrapOptions']
5050
* Setting this option to undefined (or to a function that returns undefined) will result in the first element in the focus trap's tab order receiving focus.
5151
*/
5252
initialFocus?: FocusTargetOrFalse | undefined | (() => void)
53-
avoidFocusTrap?: boolean
5453
}

src/Shared/Components/GenericModal/GenericModal.component.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,13 @@ const GenericModal = ({
8787
onEscape = noop,
8888
closeOnBackdropClick = false,
8989
children,
90-
avoidFocusTrap = false,
9190
borderVariant = 'secondary',
9291
alignCenter = false,
9392
}: PropsWithChildren<GenericModalProps>) => (
9493
<AnimatePresence>
9594
{open && (
9695
<GenericModalProvider value={{ name, onClose }}>
97-
<Backdrop
98-
onEscape={onEscape}
99-
onClick={closeOnBackdropClick ? onClose : noop}
100-
avoidFocusTrap={avoidFocusTrap}
101-
>
96+
<Backdrop onEscape={onEscape} onClick={closeOnBackdropClick ? onClose : noop}>
10297
<motion.div
10398
className={`shadow__modal flexbox-col bg__primary ${BORDER_VARIANT_TO_CLASS_NAME_MAP[borderVariant]} br-${borderRadius} dc__m-auto ${alignCenter ? '' : 'mt-40'} dc__overflow-hidden ${MODAL_WIDTH_TO_CLASS_NAME_MAP[width]}`}
10499
exit={{ y: 100, opacity: 0, scale: 0.75, transition: { duration: 0.35 } }}

0 commit comments

Comments
 (0)