Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复Dialog自定义关闭事件不清除body样式类问题 #111

Merged
merged 2 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/packages/dialog/DialogWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface DialogWrapProps {
mask?: boolean
lockScroll?: boolean
closeOnClickOverlay?: boolean
onCancel?: Function
onClosed?: Function
onCancel?: () => void
onClosed?: () => void
}

export const DialogWrap: FunctionComponent<
Expand Down
8 changes: 7 additions & 1 deletion src/packages/dialog/DialogWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ interface DialogWrapperProps {
visible?: boolean
title?: ReactNode
footer?: ReactNode
lockScroll?: boolean
onCancel?: () => void
onClosed?: () => void
}

export const DialogWrapper: FunctionComponent<
Partial<DialogWrapperProps> & HTMLAttributes<HTMLDivElement>
> = (props) => {
const { visible } = props
const { visible, lockScroll } = props
if (lockScroll && !visible && document.body.classList.value.includes('nut-overflow-hidden')) {
document.body.classList.remove('nut-overflow-hidden')
}

return (
<div style={{ display: visible ? 'block' : 'none' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/dialog/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DialogProps {
textAlign?: any
footerDirection?: string
lockScroll?: boolean
onClosed?: Function
onClosed?: () => void
onOk?: (e?: MouseEvent) => Promise<any> | void
onCancel?: () => void
onConfirm?: (e?: MouseEvent) => Promise<any> | void
Expand Down
30 changes: 25 additions & 5 deletions src/packages/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ const BaseDialog: ForwardRefRenderFunction<
unknown,
Partial<DialogProps> & HTMLAttributes<HTMLDivElement>
> = (props, ref) => {
const { visible, footer, noOkBtn, noCancelBtn, okBtnDisabled, cancelAutoClose, ...restProps } =
props
const {
visible,
footer,
noOkBtn,
noCancelBtn,
lockScroll,
okBtnDisabled,
cancelAutoClose,
okText,
cancelText,
onClosed,
onCancel,
onOk,
...restProps
} = props

const renderFooter = () => {
const { okText, cancelText, footer, lockScroll, onClosed, onCancel, onOk } = props

if (footer === null) return

const handleCancel = (e?: any) => {
Expand Down Expand Up @@ -80,7 +91,16 @@ const BaseDialog: ForwardRefRenderFunction<
return footerContent
}

return <DialogWrapper {...restProps} visible={visible} footer={renderFooter()} />
return (
<DialogWrapper
{...restProps}
visible={visible}
lockScroll={lockScroll}
footer={renderFooter()}
onClosed={onClosed}
onCancel={onCancel}
/>
)
}

export const Dialog: DialogComponent = forwardRef(BaseDialog) as DialogComponent
Expand Down
2 changes: 1 addition & 1 deletion src/packages/dialog/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ return <>
|--------|----------------|--------------|
| onOk | 确定按钮回调 | (e?: MouseEvent) => Promise | void |
| onCancel | 取消按钮回调 | () => void |
| onClosed | 关闭回调,任何情况关闭弹窗都会触发 | Function |
| onClosed | 关闭回调,任何情况关闭弹窗都会触发 | () => void |