Skip to content

Commit

Permalink
feat: 添加modalRender的属性
Browse files Browse the repository at this point in the history
test: 添加的测试用例

fix
  • Loading branch information
jhoneybee committed Aug 29, 2020
1 parent 13e4afb commit e0feade
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
31 changes: 18 additions & 13 deletions src/Dialog.tsx
Expand Up @@ -233,6 +233,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
bodyProps,
children,
destroyOnClose,
modalRender = modalNode => modalNode,
} = this.props;
const dest: any = {};
if (width !== undefined) {
Expand Down Expand Up @@ -276,6 +277,22 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
);
}

const content = (
<div className={`${prefixCls}-content`}>
{closer}
{headerNode}
<div
className={`${prefixCls}-body`}
style={bodyStyle}
ref={this.saveRef('body')}
{...bodyProps}
>
{children}
</div>
{footerNode}
</div>
)

const styleBox = { ...style, ...dest };
const sentinelStyle = { width: 0, height: 0, overflow: 'hidden', outline: 'none' };
const transitionName = this.getTransitionName();
Expand All @@ -296,19 +313,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
style={sentinelStyle}
aria-hidden="true"
/>
<div className={`${prefixCls}-content`}>
{closer}
{headerNode}
<div
className={`${prefixCls}-body`}
style={bodyStyle}
ref={this.saveRef('body')}
{...bodyProps}
>
{children}
</div>
{footerNode}
</div>
{modalRender(content)}
<div
tabIndex={0}
ref={this.saveRef('sentinelEnd')}
Expand Down
1 change: 1 addition & 0 deletions src/IDialogPropTypes.tsx
Expand Up @@ -37,6 +37,7 @@ export interface IDialogPropTypes {
wrapProps?: any;
getContainer?: IStringOrHtmlElement | (() => 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
Expand Down
16 changes: 14 additions & 2 deletions 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';
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('dialog', () => {
dialog.unmount();
jest.useRealTimers();
});

it('show', () => {
dialog.setState({ visible: true });
jest.runAllTimers();
Expand Down Expand Up @@ -425,4 +425,16 @@ describe('dialog', () => {
d.update();
expect(d.find('.rc-dialog-wrap').props().style.display).toEqual(null);
});

it('modalRender', () => {
const modalRender = mount(
<DialogWrap modalRender={node => cloneElement(node, { ...node.props, style: { background: '#1890ff' }})}>
</DialogWrap>
);
modalRender.setState({ visible: true });
jest.runAllTimers();
modalRender.update();
expect(modalRender.find('.rc-dialog-content').props().style.background).toEqual('#1890ff');
modalRender.unmount();
});
});

0 comments on commit e0feade

Please sign in to comment.