Skip to content

Commit 500af82

Browse files
committed
fix([email protected]): prevent scroll when modal container and sentinel get focused
1 parent 56a414f commit 500af82

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/Dialog/Content/Panel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
4848

4949
React.useImperativeHandle(ref, () => ({
5050
focus: () => {
51-
sentinelStartRef.current?.focus();
51+
sentinelStartRef.current?.focus({ preventScroll: true });
5252
},
5353
changeActive: (next) => {
5454
const { activeElement } = document;
5555
if (next && activeElement === sentinelEndRef.current) {
56-
sentinelStartRef.current.focus();
56+
sentinelStartRef.current.focus({ preventScroll: true });
5757
} else if (!next && activeElement === sentinelStartRef.current) {
58-
sentinelEndRef.current.focus();
58+
sentinelEndRef.current.focus({ preventScroll: true });
5959
}
6060
},
6161
}));

src/Dialog/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ export default function Dialog(props: IDialogPropTypes) {
129129
}
130130

131131
// keep focus inside dialog
132-
if (visible) {
133-
if (e.keyCode === KeyCode.TAB) {
134-
contentRef.current.changeActive(!e.shiftKey);
135-
}
132+
if (visible && e.keyCode === KeyCode.TAB) {
133+
contentRef.current.changeActive(!e.shiftKey);
136134
}
137135
}
138136

0 commit comments

Comments
 (0)