Skip to content

Commit

Permalink
fix: prevent scroll when modal container and sentinel get focused (#430)
Browse files Browse the repository at this point in the history
* fix: prevent scroll when modal container and sentinel get focused

* Update src/Dialog/index.tsx
  • Loading branch information
afc163 authored Jun 4, 2024
1 parent aa5497d commit 2f48630
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {

React.useImperativeHandle(ref, () => ({
focus: () => {
entityRef.current?.focus();
entityRef.current?.focus({ preventScroll: true });
},
changeActive: (next) => {
const { activeElement } = document;
if (next && activeElement === sentinelEndRef.current) {
sentinelStartRef.current.focus();
sentinelStartRef.current.focus({ preventScroll: true });
} else if (!next && activeElement === sentinelStartRef.current) {
sentinelEndRef.current.focus();
sentinelEndRef.current.focus({ preventScroll: true });
}
},
}));
Expand Down
6 changes: 2 additions & 4 deletions src/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => {
}

// keep focus inside dialog
if (visible) {
if (e.keyCode === KeyCode.TAB) {
contentRef.current.changeActive(!e.shiftKey);
}
if (visible && e.keyCode === KeyCode.TAB) {
contentRef.current.changeActive(!e.shiftKey);
}
}

Expand Down

0 comments on commit 2f48630

Please sign in to comment.