Skip to content

Commit

Permalink
✨ Add closing event on HdModal Overlay (#785)
Browse files Browse the repository at this point in the history
* ✨ Add closing event on HdModal Overlay

* 🎨 Rename method
  • Loading branch information
alieslamifard authored Jul 23, 2021
1 parent 1d770f4 commit 2e6f8f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/HdModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class="hd-modal"
:class="{ 'hd-modal--with-icon': withIcon }"
>
<div class="hd-modal__overlay" />
<div class="hd-modal__overlay" @click="onClose" />
<slot>
<div class="hd-modal__container">
<header class="hd-modal__header">
Expand Down Expand Up @@ -50,7 +50,7 @@
<button
v-if="isCloseButtonVisible"
class="hd-modal__close-button"
@click="$emit('close')"
@click="onClose()"
>
<hd-icon
:src="closeIcon"
Expand Down Expand Up @@ -120,7 +120,7 @@ export default {
},
},
methods: {
onCloseClick() {
onClose() {
this.$emit('close');
},
},
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/components/HdModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const TITLE_SELECTOR = '.hd-modal__title';
const BODY_SELECTOR = '.hd-modal__body';
const ACTIONS_SELECTOR = '.hd-modal__footer';
const CLOSE_BUTTON_SELECTOR = '.hd-modal__close-button';
const OVERLAY_SELECTOR = '.hd-modal__overlay';
const HEADER_SELECTOR = '.hd-modal__header';
const ICON_SELECTOR = 'hd-icon-stub';
const WITH_ICON_SELECTOR = '.hd-modal--with-icon';
Expand Down Expand Up @@ -121,4 +122,12 @@ describe('HdModal', () => {

expect(wrapper.html()).toMatchSnapshot();
});

it('renders the modal and trigger a click on the overlay', async () => {
const wrapper = wrapperBuilder();

await wrapper.find(OVERLAY_SELECTOR).trigger('click');

expect(wrapper.emitted().close).toBeTruthy();
});
});

0 comments on commit 2e6f8f8

Please sign in to comment.