Skip to content

Commit

Permalink
Close the picker on click outside #128
Browse files Browse the repository at this point in the history
  • Loading branch information
joews committed Apr 28, 2017
1 parent 0ccf0e0 commit c5fc7da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/js/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ test("closing the picker removes elements from the dom", async () => {
expect($backdrop).toBeNull();
});

test.only("the picker closes when the escape key is pressed", async () => {
test("the picker closes when the escape key is pressed", async () => {
const picker = await openPicker();

const event = new window.KeyboardEvent('keydown', { which: 27, keyCode: 27 });
window.dispatchEvent(event);

await delay(300);
const $picker = $(".c-datepicker")
const $picker = $(".c-datepicker");
expect($picker).toBeNull();
});

test("the picker closes when the scrim element is clicked", async () => {
const picker = await openPicker();

const event = new MouseEvent('click');
$(".c-scrim").dispatchEvent(event);

await delay(300);
const $picker = $(".c-datepicker");
expect($picker).toBeNull();
});

Expand Down
2 changes: 2 additions & 0 deletions lib/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class DateTimePicker extends Events {
this.$('.js-show-clock')
.addEventListener('click', e => this.clickShowClock(e), false);

this.scrimEl.addEventListener('click', () => this.close(), false);

return this;
}

Expand Down

0 comments on commit c5fc7da

Please sign in to comment.