Skip to content

Commit 0d49773

Browse files
committed
feat: notification add onClick
1 parent 8933cc5 commit 0d49773

File tree

6 files changed

+16
-3
lines changed

6 files changed

+16
-3
lines changed

components/notification/__tests__/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ describe('notification', () => {
8282
})
8383
done()
8484
})
85+
86+
it('trigger onClick', () => {
87+
notification.open({
88+
message: 'Notification Title',
89+
duration: 0,
90+
})
91+
expect(document.querySelectorAll('.ant-notification').length).toBe(1)
92+
})
8593
})

components/notification/__tests__/placement.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ describe('Notification.placement', () => {
88
return document.body.querySelectorAll(className)
99
}
1010

11-
function getStyle (el, prop, getComputedStyle, style) {
12-
getComputedStyle = getComputedStyle || window.getComputedStyle
13-
style = getComputedStyle ? getComputedStyle(el) : el.currentStyle
11+
function getStyle (el, prop) {
12+
const style = window.getComputedStyle ? window.getComputedStyle(el) : el.currentStyle
1413

1514
// If a css property's value is `auto`, it will return an empty string.
1615
return prop ? style[prop] : style

components/notification/demo/basic.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ The simplest usage that close the notification box after 4.5s.
2020
this.$notification.open({
2121
message: 'Notification Title',
2222
description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
23+
onClick: () => {
24+
console.log('Notification Clicked!');
25+
},
2326
});
2427
},
2528
}

components/notification/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The properties of config are as follows:
2323
| placement | Position of Notification, can be one of `topLeft` `topRight` `bottomLeft` `bottomRight` | string | `topRight` |
2424
| style | Customized inline style | Object \| string | - |
2525
| onClose | Specify a function that will be called when the close button is clicked | Function | - |
26+
| onClick | Specify a function that will be called when the notification is clicked | Function | - |
2627

2728
`notification` also provides a global `config()` method that can be used for specifying the default options. Once this method is used, all the notification boxes will take into account these globally defined options when displaying.
2829

components/notification/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function notice (args) {
157157
duration,
158158
closable: true,
159159
onClose: args.onClose,
160+
onClick: args.onClick,
160161
key: args.key,
161162
style: args.style || {},
162163
class: args.class,

components/notification/index.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ config 参数如下:
3131
| placement | 弹出位置,可选 `topLeft` `topRight` `bottomLeft` `bottomRight` | string | topRight |
3232
| style | 自定义内联样式 | Object \| string | - |
3333
| onClose | 点击默认关闭按钮时触发的回调函数 | Function | - |
34+
| onClick | 点击通知时触发的回调函数 | Function | - |
3435

3536
还提供了一个全局配置方法,在调用前提前配置,全局一次生效。
3637

0 commit comments

Comments
 (0)