Skip to content

Commit 582560f

Browse files
authored
feat(b-overlay): add support for overlay click event (closes #5243) (#5248)
1 parent 0c57ffe commit 582560f

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/components/overlay/overlay.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export const BOverlay = /*#__PURE__*/ Vue.extend({
146146
'position-absolute': !this.noWrap || (this.noWrap && !this.fixed),
147147
'position-fixed': this.noWrap && this.fixed
148148
},
149-
style: { ...positionCover, zIndex: this.zIndex || 10 }
149+
style: { ...positionCover, zIndex: this.zIndex || 10 },
150+
on: { click: evt => this.$emit('click', evt) }
150151
},
151152
[$background, $content]
152153
)

src/components/overlay/overlay.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,41 @@ describe('overlay', () => {
170170
wrapper.destroy()
171171
})
172172

173+
it('emits event when overlay clicked', async () => {
174+
const wrapper = mount(BOverlay, {
175+
propsData: {
176+
show: true
177+
},
178+
slots: {
179+
default: '<span>foobar</span>'
180+
}
181+
})
182+
183+
expect(wrapper.isVueInstance()).toBe(true)
184+
await waitNT(wrapper.vm)
185+
await waitRAF()
186+
await waitNT(wrapper.vm)
187+
await waitRAF()
188+
189+
expect(wrapper.is('div')).toBe(true)
190+
expect(wrapper.classes()).toContain('b-overlay-wrap')
191+
192+
const $overlay = wrapper.find('.b-overlay')
193+
expect($overlay.exists()).toBe(true)
194+
195+
expect(wrapper.emitted('click')).not.toBeDefined()
196+
197+
$overlay.trigger('click')
198+
await waitNT(wrapper.vm)
199+
200+
expect(wrapper.emitted('click')).toBeDefined()
201+
expect(wrapper.emitted('click').length).toBe(1)
202+
expect(wrapper.emitted('click')[0][0]).toBeInstanceOf(Event)
203+
expect(wrapper.emitted('click')[0][0].type).toEqual('click')
204+
205+
wrapper.destroy()
206+
})
207+
173208
it('has expected default structure when `no-wrap` is set', async () => {
174209
const wrapper = mount(BOverlay, {
175210
propsData: {

src/components/overlay/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@
7676
}
7777
],
7878
"events": [
79+
{
80+
"event": "click",
81+
"version": "2.13.0",
82+
"description": "Emitted when overlay is clicked",
83+
"args": [
84+
{
85+
"arg": "event",
86+
"type": "MouseEvent",
87+
"description": "Native click event object"
88+
}
89+
]
90+
},
7991
{
8092
"event": "shown",
8193
"description": "Emitted when the overlay has been shown"

0 commit comments

Comments
 (0)