From 9843e717fd54cc3ffa70fba6fd296d1ebbcea598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Sun, 4 Jan 2026 18:01:24 +0800 Subject: [PATCH] feat: support focusTrap --- src/Dialog/Content/Panel.tsx | 3 ++- src/IDialogPropTypes.ts | 1 + tests/focus.spec.tsx | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Dialog/Content/Panel.tsx b/src/Dialog/Content/Panel.tsx index 64f70268..9e1185b7 100644 --- a/src/Dialog/Content/Panel.tsx +++ b/src/Dialog/Content/Panel.tsx @@ -46,6 +46,7 @@ const Panel = React.forwardRef((props, ref) => { classNames: modalClassNames, styles: modalStyles, isFixedPos, + focusTrap, } = props; // ================================= Refs ================================= @@ -53,7 +54,7 @@ const Panel = React.forwardRef((props, ref) => { const internalRef = useRef(null); const mergedRef = useComposeRef(holderRef, panelRef, internalRef); - useLockFocus(visible && isFixedPos, () => internalRef.current); + useLockFocus(visible && isFixedPos && focusTrap !== false, () => internalRef.current); React.useImperativeHandle(ref, () => ({ focus: () => { diff --git a/src/IDialogPropTypes.ts b/src/IDialogPropTypes.ts index 6e7d7c02..ffe86471 100644 --- a/src/IDialogPropTypes.ts +++ b/src/IDialogPropTypes.ts @@ -58,6 +58,7 @@ export type IDialogPropTypes = { // https://github.com/ant-design/ant-design/issues/19771 // https://github.com/react-component/dialog/issues/95 focusTriggerAfterClose?: boolean; + focusTrap?: boolean; // Refs panelRef?: React.Ref; diff --git a/tests/focus.spec.tsx b/tests/focus.spec.tsx index 4fed3ecf..4f8dc44b 100644 --- a/tests/focus.spec.tsx +++ b/tests/focus.spec.tsx @@ -64,4 +64,22 @@ describe('Dialog.Focus', () => { expect(globalThis.__useLockFocusVisible).toBe(false); }); + + it('should not lock focus when focusTrap is false', () => { + render( + , + ); + + act(() => { + jest.runAllTimers(); + }); + + expect(globalThis.__useLockFocusVisible).toBe(false); + }); });