diff --git a/packages/notice-bar/en-US.md b/packages/notice-bar/en-US.md index 8e5d8c793..566ef2891 100644 --- a/packages/notice-bar/en-US.md +++ b/packages/notice-bar/en-US.md @@ -54,4 +54,5 @@ Vue.use(NoticeBar); | Event | Description | Arguments | |------|------|------| -| click | Triggered when click notice bar | - | +| click | Triggered when click NoticeBar | - | +| click | Triggered when closed | - | diff --git a/packages/notice-bar/index.js b/packages/notice-bar/index.js index 988fb78ba..8b497a645 100644 --- a/packages/notice-bar/index.js +++ b/packages/notice-bar/index.js @@ -60,7 +60,10 @@ export default sfc({ methods: { onClickIcon() { - this.showNoticeBar = this.mode !== 'closeable'; + if (this.mode === 'closeable') { + this.showNoticeBar = false; + this.$emit('close'); + } }, onAnimationEnd() { diff --git a/packages/notice-bar/test/index.spec.js b/packages/notice-bar/test/index.spec.js new file mode 100644 index 000000000..2352815b5 --- /dev/null +++ b/packages/notice-bar/test/index.spec.js @@ -0,0 +1,14 @@ +import NoticeBar from '..'; +import { mount } from '../../../test/utils'; + +test('close event', () => { + const wrapper = mount(NoticeBar, { + propsData: { + mode: 'closeable' + } + }); + const close = wrapper.find('.van-notice-bar__right-icon'); + + close.trigger('click'); + expect(wrapper.emitted('close')).toBeTruthy(); +}); diff --git a/packages/notice-bar/zh-CN.md b/packages/notice-bar/zh-CN.md index af89221d7..9ce6aba84 100644 --- a/packages/notice-bar/zh-CN.md +++ b/packages/notice-bar/zh-CN.md @@ -58,4 +58,5 @@ Vue.use(NoticeBar); | 事件名 | 说明 | 参数 | |------|------|------| -| click | 点击事件回调 | - | +| click | 点击时触发 | - | +| close | 关闭时触发 | - |