diff --git a/components/notification/__tests__/index.test.js b/components/notification/__tests__/index.test.js index 47238e463..04e800931 100644 --- a/components/notification/__tests__/index.test.js +++ b/components/notification/__tests__/index.test.js @@ -82,4 +82,12 @@ describe('notification', () => { }) done() }) + + it('trigger onClick', () => { + notification.open({ + message: 'Notification Title', + duration: 0, + }) + expect(document.querySelectorAll('.ant-notification').length).toBe(1) + }) }) diff --git a/components/notification/__tests__/placement.test.js b/components/notification/__tests__/placement.test.js index d8bb7263d..3df336d93 100644 --- a/components/notification/__tests__/placement.test.js +++ b/components/notification/__tests__/placement.test.js @@ -8,9 +8,8 @@ describe('Notification.placement', () => { return document.body.querySelectorAll(className) } - function getStyle (el, prop, getComputedStyle, style) { - getComputedStyle = getComputedStyle || window.getComputedStyle - style = getComputedStyle ? getComputedStyle(el) : el.currentStyle + function getStyle (el, prop) { + const style = window.getComputedStyle ? window.getComputedStyle(el) : el.currentStyle // If a css property's value is `auto`, it will return an empty string. return prop ? style[prop] : style diff --git a/components/notification/demo/basic.md b/components/notification/demo/basic.md index d34fffc6c..609f2ebe3 100644 --- a/components/notification/demo/basic.md +++ b/components/notification/demo/basic.md @@ -20,6 +20,9 @@ The simplest usage that close the notification box after 4.5s. this.$notification.open({ message: 'Notification Title', description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.', + onClick: () => { + console.log('Notification Clicked!'); + }, }); }, } diff --git a/components/notification/index.en-US.md b/components/notification/index.en-US.md index 57e89b79b..f08ccc07d 100644 --- a/components/notification/index.en-US.md +++ b/components/notification/index.en-US.md @@ -23,6 +23,7 @@ The properties of config are as follows: | placement | Position of Notification, can be one of `topLeft` `topRight` `bottomLeft` `bottomRight` | string | `topRight` | | style | Customized inline style | Object \| string | - | | onClose | Specify a function that will be called when the close button is clicked | Function | - | +| onClick | Specify a function that will be called when the notification is clicked | Function | - | `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. diff --git a/components/notification/index.js b/components/notification/index.js index 5bb551415..5819ac5b5 100644 --- a/components/notification/index.js +++ b/components/notification/index.js @@ -157,6 +157,7 @@ function notice (args) { duration, closable: true, onClose: args.onClose, + onClick: args.onClick, key: args.key, style: args.style || {}, class: args.class, diff --git a/components/notification/index.zh-CN.md b/components/notification/index.zh-CN.md index ae8f0ef6c..f596c815a 100644 --- a/components/notification/index.zh-CN.md +++ b/components/notification/index.zh-CN.md @@ -31,6 +31,7 @@ config 参数如下: | placement | 弹出位置,可选 `topLeft` `topRight` `bottomLeft` `bottomRight` | string | topRight | | style | 自定义内联样式 | Object \| string | - | | onClose | 点击默认关闭按钮时触发的回调函数 | Function | - | +| onClick | 点击通知时触发的回调函数 | Function | - | 还提供了一个全局配置方法,在调用前提前配置,全局一次生效。