ant-design/components/notification/demo/duration.md

35 lines
987 B
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 1
title:
2016-08-17 11:07:02 +08:00
zh-CN: 自动关闭的延时
en-US: Duration after which the notification box is closed
2016-03-31 09:40:55 +08:00
---
2015-08-03 15:17:12 +08:00
2016-08-17 11:07:02 +08:00
## zh-CN
2020-11-08 15:04:02 +08:00
自定义通知框自动关闭的延时,默认 `4.5s`,取消自动关闭只要将该值设为 `0` 即可。
2015-08-03 15:17:12 +08:00
2016-08-17 11:07:02 +08:00
## en-US
2019-05-07 14:57:32 +08:00
`Duration` can be used to specify how long the notification stays open. After the duration time elapses, the notification closes automatically. If not specified, default value is 4.5 seconds. If you set the value to 0, the notification box will never close automatically.
2016-08-17 11:07:02 +08:00
2019-05-07 14:57:32 +08:00
```jsx
import { Button, notification } from 'antd';
2015-08-03 15:17:12 +08:00
2016-12-14 17:57:15 +08:00
const openNotification = () => {
const args = {
message: 'Notification Title',
2019-05-07 14:57:32 +08:00
description:
'I will never close automatically. This is a purposely very very long description that has many many characters and words.',
2016-05-11 09:32:33 +08:00
duration: 0,
2015-08-03 15:17:12 +08:00
};
notification.open(args);
};
export default () => (
2019-05-07 14:57:32 +08:00
<Button type="primary" onClick={openNotification}>
Open the notification box
</Button>
2018-11-28 15:00:03 +08:00
);
2019-05-07 14:57:32 +08:00
```