瀏覽代碼

Fix modal method left useless div after unmount (#775)

代强 3 年之前
父節點
當前提交
9a2f96a4d9
共有 4 個文件被更改,包括 65 次插入63 次删除
  1. 30 30
      content/show/modal/index-en-US.md
  2. 32 32
      content/show/modal/index.md
  3. 2 0
      packages/semi-ui/modal/Modal.tsx
  4. 1 1
      packages/semi-ui/modal/confirm.tsx

+ 30 - 30
content/show/modal/index-en-US.md

@@ -560,40 +560,40 @@ function Demo(props = {}) {
 
 ### Modal
 
-| Properties        | Instructions                                       | type      | Default |
-| ----------------- | -------------------------------------------------- | --------- | ------- |
-| afterClose             | Callback function when modal closed completely   <br/>**>= v1.16.0**           | () => void  | -    |
-| bodyStyle         | Content style                                      | CSSProperties    | -       |
-| cancelButtonProps | Properties for cancel button                       | [ButtonProps](/en-US/input/button#API-reference)    | -       |
-| cancelText        | Text for cancel button                             | string    | -       |
-| centered          | Toggle whether to center modal                     | boolean   | false   |
-| closable          | Toggle whether to show close button                | boolean   | true    |
-| closeIcon         | Icon for close button  <br/>**>= v1.0.0** | ReactNode   | <IconClose /\>    |
+| Properties        | Instructions                                       | type | Default |
+| ----------------- | -------------------------------------------------- | -- | ------- |
+| afterClose             | Callback function when modal closed completely   <br/>**>= v1.16.0**           | () => void | -    |
+| bodyStyle         | Content style                                      | CSSProperties | -       |
+| cancelButtonProps | Properties for cancel button                       | [ButtonProps](/en-US/input/button#API-reference) | -       |
+| cancelText        | Text for cancel button                             | string | -       |
+| centered          | Toggle whether to center modal                     | boolean | false   |
+| closable          | Toggle whether to show close button                | boolean | true    |
+| closeIcon         | Icon for close button  <br/>**>= v1.0.0** | ReactNode | <IconClose /\>    |
 | closeOnEsc        | Toggle whether to allow close modal by keyboard event Esc  <br/>**>= v1.0.0** | boolean | false       | 
-| confirmLoading    | Toggle loading state of confirm button             | boolean   | false   |
-| content            | Content            | ReactNode         | -      |
+| confirmLoading    | Toggle loading state of confirm button             | boolean | false   |
+| content            | Content            | ReactNode  | -      |
 | footer            | Footer                                             | ReactNode | -       |
-| fullScreen        | Is modal FullScreen(will override width and height) <br/>**>= v1.18.0**      | boolean            | false      |
+| fullScreen        | Is modal FullScreen(will override width and height) <br/>**>= v1.18.0**      | boolean     | false      |
 | getPopupContainer | Specifies the parent DOM, and the bullet layer will be rendered to the DOM, you need to set 'position: relative` <br/>** >= v0.33.0 **  | () => HTMLElement |() => document.body |   
-| hasCancel        | Toggle whether to show cancal button               | boolean    | true      |
+| hasCancel        | Toggle whether to show cancal button               | boolean | true      |
 | header            | Header                                             | ReactNode | -       |
-| height            | Height                                             | number    | -       |
+| height            | Height                                             | number | -       |
 | icon              | Custom icon       <br/>**v1.1.0**                                          | ReactNode | -       |
-| keepDOM | Keep dom tree when close modal <br/>**>= v1.0.0**  | boolean  | false |
-| lazyRender | Lazy render modal, used with `keepDOM` <br/>**>=v1.0.0**  | boolean  | true |      
-| mask              | Toggle whether to show mask                        | boolean   | true    |
-| maskClosable      | Toggle whether to allow closing when clicking mask | boolean   | true    |
-| maskStyle         | Mask style                                         | CSSProperties    | -       |
-| motion            | animation switch           | object \| boolean | true    |
-| okButtonProps     | Properties for confirm button                      | [ButtonProps](/en-US/input/button#API-reference)    | -       |
-| okText            | Text for confirm button                            | string    | -       |
-| okType            | Type for confirm button, optional: 'primary'、'secondary'、'tertiary'、'warning'、'danger'                            | string    | primary |
-| size | Size of modal, one of `small`(448px), `medium`(684px), `large`(920px), `full-width`(100vw - 64px) <br/>**>= v1.0.0**  | string  | 'small' |
-| style             | Inline style                                       | CSSProperties    | -       |
-| title             | Title                                              | ReactNode    | -       |
-| visible           | Toggle visibility of the modal                     | boolean   | false   |
-| width             | Width                                              | number    | 448     |
-| zIndex            | Z-index value for mask                             | number    | 1000    |
+| keepDOM | Keep dom tree when close modal <br/>**>= v1.0.0**  | boolean | false |
+| lazyRender | Lazy render modal, used with `keepDOM` <br/>**>=v1.0.0**  | boolean | true |      
+| mask              | Toggle whether to show mask                        | boolean | true    |
+| maskClosable      | Toggle whether to allow closing when clicking mask | boolean | true    |
+| maskStyle         | Mask style                                         | CSSProperties | -       |
+| motion            | animation switch           | boolean | true    |
+| okButtonProps     | Properties for confirm button                      | [ButtonProps](/en-US/input/button#API-reference) | -       |
+| okText            | Text for confirm button                            | string | -       |
+| okType            | Type for confirm button, optional: 'primary'、'secondary'、'tertiary'、'warning'、'danger'                            | string | primary |
+| size | Size of modal, one of `small`(448px), `medium`(684px), `large`(920px), `full-width`(100vw - 64px) <br/>**>= v1.0.0**  | string | 'small' |
+| style             | Inline style                                       | CSSProperties | -       |
+| title             | Title                                              | ReactNode | -       |
+| visible           | Toggle visibility of the modal                     | boolean | false   |
+| width             | Width                                              | number | 448     |
+| zIndex            | Z-index value for mask                             | number | 1000    |
 | onCancel          | Callback function when clicking cancel button      | (e: any) => void \| Promise<any\>  | -       |
 | onOk              | Callback function when clicking confirm button     | (e: any) => void \| Promise<any\>  | -       |
 
@@ -664,4 +664,4 @@ When you need access Context, you could use `Modal.useModal` to create a `contex
 <!-- ## Related Material
 ```material
 1, 55
-``` -->
+``` -->

+ 32 - 32
content/show/modal/index.md

@@ -564,41 +564,41 @@ function Demo(props = {}) {
 
 ### Modal
 
-| 属性              | 说明                             | 类型      | 默认值  |
-| ----------------- | -------------------------------- | --------- | ------- |
-| afterClose         | 对话框完全关闭后的回调函数   <br/>**v1.16.0 后提供**           | () => void    | 无      |
-| bodyStyle         | 对话框内容的样式                 | CSSProperties    | 无      |
-| cancelButtonProps | 取消按钮的 props                 | [ButtonProps](/zh-CN/input/button#API参考)    | 无      |
-| cancelText        | 取消按钮的文字                   | string    | 无      |
-| centered          | 是否居中显示                     | boolean   | false   |
-| className         | 可用于设置样式类名               | string    | 无      |
-| closable          | 是否显示右上角的关闭按钮         | boolean   | true    |
-| closeIcon            | 关闭按钮的icon  <br/>**v1.0.0 后提供**                                              | ReactNode            | <IconClose /\>    |
+| 属性              | 说明                             | 类型 | 默认值  |
+| ----------------- | -------------------------------- | -- | ------- |
+| afterClose         | 对话框完全关闭后的回调函数   <br/>**v1.16.0 后提供**           | () => void | 无      |
+| bodyStyle         | 对话框内容的样式                 | CSSProperties | 无      |
+| cancelButtonProps | 取消按钮的 props                 | [ButtonProps](/zh-CN/input/button#API参考) | 无      |
+| cancelText        | 取消按钮的文字                   | string | 无      |
+| centered          | 是否居中显示                     | boolean | false   |
+| className         | 可用于设置样式类名               | string | 无      |
+| closable          | 是否显示右上角的关闭按钮         | boolean | true    |
+| closeIcon            | 关闭按钮的icon  <br/>**v1.0.0 后提供**                                              | ReactNode     | <IconClose /\>    |
 | closeOnEsc              | 允许通过键盘事件Esc触发关闭  <br/>**v1.0.0 后提供**                                               | boolean | false       | 
-| confirmLoading    | 确认按钮 loading                 | boolean   | false   |
-| content            | 对话框内容            | ReactNode         | 无      |
+| confirmLoading    | 确认按钮 loading                 | boolean | false   |
+| content            | 对话框内容            | ReactNode  | 无      |
 | footer            | 对话框底部                       | ReactNode | 无      |
-| fullScreen        | 对话是否是全屏(会覆盖 width height)  <br/>**v1.18.0 后提供**                          | boolean            | false      |
-| getPopupContainer | 指定父级 DOM,弹层将会渲染至该 DOM 中,自定义需要设置 `position: relative` <br/>**v0.33.0 后提供**  | () => HTMLElement  | () => document.body |     
-| hasCancel        | 是否显示取消按钮                  | boolean    | true      |
+| fullScreen        | 对话是否是全屏(会覆盖 width height)  <br/>**v1.18.0 后提供**                          | boolean     | false      |
+| getPopupContainer | 指定父级 DOM,弹层将会渲染至该 DOM 中,自定义需要设置 `position: relative` <br/>**v0.33.0 后提供**  | () => HTMLElement | () => document.body |     
+| hasCancel        | 是否显示取消按钮                  | boolean | true      |
 | header            | 对话框头部                       | ReactNode | 无      |
-| height            | 高度                             | number    | 无      |
+| height            | 高度                             | number | 无      |
 | icon              | 自定义icon       <br/>**v1.1.0 后提供**                                          | ReactNode | -       |
-| keepDOM | 关闭对话框时是否销毁 <br/>**v1.0.0 后提供**  | boolean  | false |
-| lazyRender | 配合 keepDOM 使用,为 true 时挂载时不会渲染对话框组件 <br/>**v1.0.0 后提供**  | boolean  | true |   
-| mask              | 是否显示遮罩                     | boolean   | true    |
-| maskClosable      | 是否允许通过点击遮罩来关闭对话框 | boolean   | true    |
-| maskStyle         | 遮罩的样式                       | CSSProperties    | 无      |
-| motion         | 动画效果开关                      | object\|boolean    | true      |
-| okButtonProps     | 确认按钮的 props                 | [ButtonProps](/zh-CN/input/button#API参考)    | 无      |
-| okText            | 确认按钮的文字                   | string    | 无      |
-| okType            | 确认按钮的类型, 可选: 'primary'、'secondary'、'tertiary'、'warning'、'danger'                   | string    | primary |
-| size | 对话框宽度尺寸,支持 `small`(448px), `medium`(684px), `large`(920px),`full-width`(100vw - 64px) <br/>**v1.0.0 后提供**  | string  | 'small' |     
-| style             | 可用于设置样式                   | CSSProperties    | 无      |
-| title             | 对话框的标题                     | ReactNode    | 无      |
-| visible           | 对话框是否可见                   | boolean   | false   |
-| width             | 宽度                             | number    | 448     |
-| zIndex            | 遮罩的 z-index 值                | number    | 1000    |
+| keepDOM | 关闭对话框时是否销毁 <br/>**v1.0.0 后提供**  | boolean | false |
+| lazyRender | 配合 keepDOM 使用,为 true 时挂载时不会渲染对话框组件 <br/>**v1.0.0 后提供**  | boolean | true |   
+| mask              | 是否显示遮罩                     | boolean | true    |
+| maskClosable      | 是否允许通过点击遮罩来关闭对话框 | boolean | true    |
+| maskStyle         | 遮罩的样式                       | CSSProperties | 无      |
+| motion         | 动画效果开关                      | boolean    | true      |
+| okButtonProps     | 确认按钮的 props                 | [ButtonProps](/zh-CN/input/button#API参考) | 无      |
+| okText            | 确认按钮的文字                   | string | 无      |
+| okType            | 确认按钮的类型, 可选: 'primary'、'secondary'、'tertiary'、'warning'、'danger'                   | string | primary |
+| size | 对话框宽度尺寸,支持 `small`(448px), `medium`(684px), `large`(920px),`full-width`(100vw - 64px) <br/>**v1.0.0 后提供**  | string | 'small' |     
+| style             | 可用于设置样式                   | CSSProperties | 无      |
+| title             | 对话框的标题                     | ReactNode | 无      |
+| visible           | 对话框是否可见                   | boolean | false   |
+| width             | 宽度                             | number | 448     |
+| zIndex            | 遮罩的 z-index 值                | number | 1000    |
 | onCancel          | 取消对话框时的回调函数           | (e: any) => void \| Promise<any\>  | 无      |
 | onOk              | 点击确认按钮时的回调函数         | (e: any) => void \| Promise<any\>  | 无      |
 
@@ -671,4 +671,4 @@ modal.destroy();
 <!-- ## 相关物料
 ```material
 1, 55
-``` -->
+``` -->

+ 2 - 0
packages/semi-ui/modal/Modal.tsx

@@ -15,6 +15,7 @@ import confirm, { withConfirm, withError, withInfo, withSuccess, withWarning } f
 import { Locale } from '../locale/interface';
 import useModal from './useModal';
 import { ButtonProps } from '../button/Button';
+import { MotionObject } from "@douyinfe/semi-foundation/utils/type";
 
 export const destroyFns: any[] = [];
 export type ConfirmType = 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom';
@@ -156,6 +157,7 @@ class Modal extends BaseComponent<ModalReactProps, ModalState> {
                 this.props.onOk(e);
             },
             notifyClose: () => {
+                (this.props.motion as MotionObject)?.didLeave?.();
                 this.props.afterClose();
             },
             toggleHidden: (hidden: boolean, callback?: (hidden: boolean) => void) => {

+ 1 - 1
packages/semi-ui/modal/confirm.tsx

@@ -118,4 +118,4 @@ export function withConfirm(props: ModalReactProps) {
         icon: <IconHelpCircle />,
         ...props
     };
-}
+}