Skip to content

Commit 2f48630

Browse files
authored
fix: prevent scroll when modal container and sentinel get focused (#430)
* fix: prevent scroll when modal container and sentinel get focused * Update src/Dialog/index.tsx
1 parent aa5497d commit 2f48630

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
@@ -59,14 +59,14 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
5959

6060
React.useImperativeHandle(ref, () => ({
6161
focus: () => {
62-
entityRef.current?.focus();
62+
entityRef.current?.focus({ preventScroll: true });
6363
},
6464
changeActive: (next) => {
6565
const { activeElement } = document;
6666
if (next && activeElement === sentinelEndRef.current) {
67-
sentinelStartRef.current.focus();
67+
sentinelStartRef.current.focus({ preventScroll: true });
6868
} else if (!next && activeElement === sentinelStartRef.current) {
69-
sentinelEndRef.current.focus();
69+
sentinelEndRef.current.focus({ preventScroll: true });
7070
}
7171
},
7272
}));

src/Dialog/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,8 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => {
143143
}
144144

145145
// keep focus inside dialog
146-
if (visible) {
147-
if (e.keyCode === KeyCode.TAB) {
148-
contentRef.current.changeActive(!e.shiftKey);
149-
}
146+
if (visible && e.keyCode === KeyCode.TAB) {
147+
contentRef.current.changeActive(!e.shiftKey);
150148
}
151149
}
152150

0 commit comments

Comments
 (0)