Skip to content

Commit

Permalink
Merge 395a42a into 8633d9b
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Mar 12, 2021
2 parents 8633d9b + 395a42a commit ad6e8e7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 26 deletions.
31 changes: 18 additions & 13 deletions components/modal/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
closeIcon,
modalRender,
focusTriggerAfterClose,
footer,
} = props;

devWarning(
Expand Down Expand Up @@ -113,19 +114,23 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
<div className={`${contentPrefixCls}-content`}>{props.content}</div>
</div>
</ConfigProvider>
<div className={`${contentPrefixCls}-btns`}>
{cancelButton}
<ActionButton
type={okType}
actionFn={onOk}
closeModal={close}
autoFocus={autoFocusButton === 'ok'}
buttonProps={okButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{okText}
</ActionButton>
</div>
{footer === undefined ? (
<div className={`${contentPrefixCls}-btns`}>
{cancelButton}
<ActionButton
type={okType}
actionFn={onOk}
closeModal={close}
autoFocus={autoFocusButton === 'ok'}
buttonProps={okButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{okText}
</ActionButton>
</div>
) : (
footer
)}
</div>
</Dialog>
);
Expand Down
1 change: 1 addition & 0 deletions components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface ModalFuncProps {
cancelButtonProps?: ButtonProps;
centered?: boolean;
width?: string | number;
footer?: React.ReactNode;
okText?: React.ReactNode;
okType?: LegacyButtonType;
cancelText?: React.ReactNode;
Expand Down
39 changes: 32 additions & 7 deletions components/modal/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,39 @@ exports[`renders ./components/modal/demo/dark.md correctly 1`] = `
`;

exports[`renders ./components/modal/demo/footer.md correctly 1`] = `
<button
class="ant-btn ant-btn-primary"
type="button"
<div
class="ant-space ant-space-horizontal ant-space-align-center"
>
<span>
Open Modal with customized footer
</span>
</button>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Open Modal with customized footer
</span>
</button>
</div>
<div
class="ant-space-item"
style="margin-right:8px"
/>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Confirm without footer
</span>
</button>
</div>
</div>
`;

exports[`renders ./components/modal/demo/hooks.md correctly 1`] = `
Expand Down
11 changes: 11 additions & 0 deletions components/modal/__tests__/confirm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ describe('Modal.confirm triggers callbacks correctly', () => {
jest.useRealTimers();
});

it('should not render footer when footer is null', () => {
jest.useFakeTimers();
confirm({
content: 'some descriptions',
footer: null,
});
jest.runAllTimers();
expect(document.querySelector('.ant-modal-confirm-btns')).toBe(null);
jest.useRealTimers();
});

it('trigger onCancel once when click on cancel button', () => {
const onCancel = jest.fn();
const onOk = jest.fn();
Expand Down
26 changes: 23 additions & 3 deletions components/modal/demo/footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A more complex example which define a customized footer button bar. The dialog w
You could set `footer` to `null` if you don't need default footer buttons.

```jsx
import { Modal, Button } from 'antd';
import { Modal, Button, Space } from 'antd';

class App extends React.Component {
state = {
Expand All @@ -43,10 +43,26 @@ class App extends React.Component {
this.setState({ visible: false });
};

openConfirmWithoutFooter = () => {
Modal.confirm({
content: (
<>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</>
),
maskClosable: true,
footer: null,
});
};

render() {
const { visible, loading } = this.state;
return (
<>
<Space>
<Button type="primary" onClick={this.showModal}>
Open Modal with customized footer
</Button>
Expand Down Expand Up @@ -79,7 +95,11 @@ class App extends React.Component {
<p>Some contents...</p>
<p>Some contents...</p>
</Modal>
</>

<Button type="primary" onClick={this.openConfirmWithoutFooter}>
Confirm without footer
</Button>
</Space>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions components/modal/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/3StSdUlSH/Modal.svg
| getContainer | 指定 Modal 挂载的 HTML 节点, false 为挂载在当前 dom | HTMLElement \| () => HTMLElement \| Selectors \| false | document.body | |
| keyboard | 是否支持键盘 esc 关闭 | boolean | true | |
| mask | 是否展示遮罩 | boolean | true | |
| maskClosable | 点击蒙层是否允许关闭 | boolean | true | |
| maskClosable | 点击蒙层是否允许关闭 | boolean | false | |
| maskStyle | 遮罩样式 | CSSProperties | | |
| modalRender | 自定义渲染对话框 | (node: ReactNode) => ReactNode | - | 4.7.0 |
| okButtonProps | ok 按钮 props | [ButtonProps](/components/button/#API) | - | |
Expand Down Expand Up @@ -128,7 +128,7 @@ browserHistory.listen(() => {

### Modal.useModal()

当你需要使用 Context 时,可以通过 `Modal.useModal` 创建一个 `contextHolder` 插入子节点中。通过 hooks 创建的临时 Modal 将会得到 `contextHolder` 所在位置的所有上下文。创建的 `modal` 对象拥有与 [`Modal.method`](#Modal.method()) 相同的创建通知方法。
当你需要使用 Context 时,可以通过 `Modal.useModal` 创建一个 `contextHolder` 插入子节点中。通过 hooks 创建的临时 Modal 将会得到 `contextHolder` 所在位置的所有上下文。创建的 `modal` 对象拥有与 [`Modal.method`](<#Modal.method()>) 相同的创建通知方法。

```jsx
const [modal, contextHolder] = Modal.useModal();
Expand Down Expand Up @@ -172,4 +172,4 @@ return (

### 静态方法如何设置 prefixCls ?

你可以通过 [`ConfigProvider.config`](/components/config-provider/#ConfigProvider.config()-4.13.0+) 进行设置。
你可以通过 [`ConfigProvider.config`](</components/config-provider/#ConfigProvider.config()-4.13.0+>) 进行设置。

0 comments on commit ad6e8e7

Please sign in to comment.