Skip to content

Commit

Permalink
fix(dialog): 多个弹窗关闭一个后出现滚动条
Browse files Browse the repository at this point in the history
多个弹窗关闭一个后出现滚动条

fix #382
  • Loading branch information
psaren authored and shalompeng committed Feb 24, 2022
1 parent e6799de commit e7f53c5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/dialog/RenderDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const RenderDialog: React.FC<RenderDialogProps> = (props) => {
const bodyCssTextRef = useRef<string>();
const isModal = mode === 'modal';
const canDraggable = props.draggable && mode === 'modeless';
const dialogOpenClass = `${prefixCls}__open`;

useEffect(() => {
bodyOverflow.current = document.body.style.overflow;
Expand Down Expand Up @@ -81,9 +82,12 @@ const RenderDialog: React.FC<RenderDialogProps> = (props) => {
wrap.current.focus();
}
} else if (isModal) {
document.body.style.cssText = bodyCssTextRef.current;
const openDialogDom = document.querySelectorAll(`.${dialogOpenClass}`);
if (openDialogDom.length < 1) {
document.body.style.cssText = bodyCssTextRef.current;
}
}
}, [preventScrollThrough, attach, visible, mode, isModal]);
}, [preventScrollThrough, attach, visible, mode, isModal, dialogOpenClass]);

useEffect(() => {
if (visible) {
Expand All @@ -101,7 +105,10 @@ const RenderDialog: React.FC<RenderDialogProps> = (props) => {
}
if (isModal && preventScrollThrough) {
// 还原body的滚动条
isModal && (document.body.style.overflow = bodyOverflow.current);
const openDialogDom = document.querySelectorAll(`.${dialogOpenClass}`);
if (isModal && openDialogDom.length < 1) {
document.body.style.overflow = bodyOverflow.current;
}
}
if (!isModal) {
const { style } = dialog.current;
Expand Down Expand Up @@ -262,7 +269,12 @@ const RenderDialog: React.FC<RenderDialogProps> = (props) => {
};

const dialogBody = renderDialog(`${props.placement ? `${prefixCls}--${props.placement}` : ''}`);
const wrapClass = classnames(props.className, `${prefixCls}__ctx`, `${prefixCls}__ctx--fixed`);
const wrapClass = classnames(
props.className,
`${prefixCls}__ctx`,
`${prefixCls}__ctx--fixed`,
visible ? dialogOpenClass : '',
);
const dialog = (
<div ref={wrap} className={wrapClass} style={wrapStyle} onKeyDown={handleKeyDown}>
{mode === 'modal' && renderMask()}
Expand Down

0 comments on commit e7f53c5

Please sign in to comment.