Skip to content

Commit 9843e71

Browse files
committed
feat: support focusTrap
1 parent 18678e8 commit 9843e71

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Dialog/Content/Panel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
4646
classNames: modalClassNames,
4747
styles: modalStyles,
4848
isFixedPos,
49+
focusTrap,
4950
} = props;
5051

5152
// ================================= Refs =================================
5253
const { panel: panelRef } = React.useContext(RefContext);
5354
const internalRef = useRef<HTMLDivElement>(null);
5455
const mergedRef = useComposeRef(holderRef, panelRef, internalRef);
5556

56-
useLockFocus(visible && isFixedPos, () => internalRef.current);
57+
useLockFocus(visible && isFixedPos && focusTrap !== false, () => internalRef.current);
5758

5859
React.useImperativeHandle(ref, () => ({
5960
focus: () => {

src/IDialogPropTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type IDialogPropTypes = {
5858
// https://github.com/ant-design/ant-design/issues/19771
5959
// https://github.com/react-component/dialog/issues/95
6060
focusTriggerAfterClose?: boolean;
61+
focusTrap?: boolean;
6162

6263
// Refs
6364
panelRef?: React.Ref<HTMLDivElement>;

tests/focus.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,22 @@ describe('Dialog.Focus', () => {
6464

6565
expect(globalThis.__useLockFocusVisible).toBe(false);
6666
});
67+
68+
it('should not lock focus when focusTrap is false', () => {
69+
render(
70+
<Dialog
71+
visible
72+
focusTrap={false}
73+
styles={{
74+
wrapper: { position: 'fixed' },
75+
}}
76+
/>,
77+
);
78+
79+
act(() => {
80+
jest.runAllTimers();
81+
});
82+
83+
expect(globalThis.__useLockFocusVisible).toBe(false);
84+
});
6785
});

0 commit comments

Comments
 (0)