Skip to content
Permalink
Browse files
feat(b-overlay): add support for overlay click event (closes #5243) (
  • Loading branch information
jacobmllr95 committed Apr 26, 2020
1 parent 0c57ffe commit 582560ff97690ab1e5c1f609d76804b7b3daa104
Showing 3 changed files with 49 additions and 1 deletion.
@@ -146,7 +146,8 @@ export const BOverlay = /*#__PURE__*/ Vue.extend({
'position-absolute': !this.noWrap || (this.noWrap && !this.fixed),
'position-fixed': this.noWrap && this.fixed
},
style: { ...positionCover, zIndex: this.zIndex || 10 }
style: { ...positionCover, zIndex: this.zIndex || 10 },
on: { click: evt => this.$emit('click', evt) }
},
[$background, $content]
)
@@ -170,6 +170,41 @@ describe('overlay', () => {
wrapper.destroy()
})

it('emits event when overlay clicked', async () => {
const wrapper = mount(BOverlay, {
propsData: {
show: true
},
slots: {
default: '<span>foobar</span>'
}
})

expect(wrapper.isVueInstance()).toBe(true)
await waitNT(wrapper.vm)
await waitRAF()
await waitNT(wrapper.vm)
await waitRAF()

expect(wrapper.is('div')).toBe(true)
expect(wrapper.classes()).toContain('b-overlay-wrap')

const $overlay = wrapper.find('.b-overlay')
expect($overlay.exists()).toBe(true)

expect(wrapper.emitted('click')).not.toBeDefined()

$overlay.trigger('click')
await waitNT(wrapper.vm)

expect(wrapper.emitted('click')).toBeDefined()
expect(wrapper.emitted('click').length).toBe(1)
expect(wrapper.emitted('click')[0][0]).toBeInstanceOf(Event)
expect(wrapper.emitted('click')[0][0].type).toEqual('click')

wrapper.destroy()
})

it('has expected default structure when `no-wrap` is set', async () => {
const wrapper = mount(BOverlay, {
propsData: {
@@ -76,6 +76,18 @@
}
],
"events": [
{
"event": "click",
"version": "2.13.0",
"description": "Emitted when overlay is clicked",
"args": [
{
"arg": "event",
"type": "MouseEvent",
"description": "Native click event object"
}
]
},
{
"event": "shown",
"description": "Emitted when the overlay has been shown"

0 comments on commit 582560f

Please sign in to comment.