From e0feade10ec4227195279e494c14509fc3154aff Mon Sep 17 00:00:00 2001 From: jhoneybee Date: Sat, 29 Aug 2020 19:27:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0modalRender=E7=9A=84?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test: 添加的测试用例 fix --- src/Dialog.tsx | 31 ++++++++++++++++++------------- src/IDialogPropTypes.tsx | 1 + tests/index.spec.js | 16 ++++++++++++++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Dialog.tsx b/src/Dialog.tsx index 485c77d3..df1b12f6 100644 --- a/src/Dialog.tsx +++ b/src/Dialog.tsx @@ -233,6 +233,7 @@ export default class Dialog extends React.Component { bodyProps, children, destroyOnClose, + modalRender = modalNode => modalNode, } = this.props; const dest: any = {}; if (width !== undefined) { @@ -276,6 +277,22 @@ export default class Dialog extends React.Component { ); } + const content = ( +
+ {closer} + {headerNode} +
+ {children} +
+ {footerNode} +
+ ) + const styleBox = { ...style, ...dest }; const sentinelStyle = { width: 0, height: 0, overflow: 'hidden', outline: 'none' }; const transitionName = this.getTransitionName(); @@ -296,19 +313,7 @@ export default class Dialog extends React.Component { style={sentinelStyle} aria-hidden="true" /> -
- {closer} - {headerNode} -
- {children} -
- {footerNode} -
+ {modalRender(content)}
IStringOrHtmlElement) | false; closeIcon?: ReactNode; + modalRender?: (node: ReactNode) => ReactNode; forceRender?: boolean; // https://github.com/ant-design/ant-design/issues/19771 // https://github.com/react-component/dialog/issues/95 diff --git a/tests/index.spec.js b/tests/index.spec.js index 7374756b..d4be2e3b 100644 --- a/tests/index.spec.js +++ b/tests/index.spec.js @@ -1,6 +1,6 @@ /* eslint-disable react/no-render-return-value */ /* eslint-disable func-names */ -import React from 'react'; +import React, { cloneElement } from 'react'; import { mount } from 'enzyme'; import KeyCode from 'rc-util/lib/KeyCode'; @@ -50,7 +50,7 @@ describe('dialog', () => { dialog.unmount(); jest.useRealTimers(); }); - + it('show', () => { dialog.setState({ visible: true }); jest.runAllTimers(); @@ -425,4 +425,16 @@ describe('dialog', () => { d.update(); expect(d.find('.rc-dialog-wrap').props().style.display).toEqual(null); }); + + it('modalRender', () => { + const modalRender = mount( + cloneElement(node, { ...node.props, style: { background: '#1890ff' }})}> + + ); + modalRender.setState({ visible: true }); + jest.runAllTimers(); + modalRender.update(); + expect(modalRender.find('.rc-dialog-content').props().style.background).toEqual('#1890ff'); + modalRender.unmount(); + }); });