Skip to content

Commit 03c9889

Browse files
authored
Merge branch 'master' into translate
2 parents 6ec72fe + 476b08b commit 03c9889

11 files changed

+160
-51
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The picker is decoupled from any single form element for simplicity. However, it
7070
import MaterialDateTimePicker from 'material-datetime-picker';
7171

7272
const input = document.querySelector('.c-datepicker-input');
73-
const picker = new MaterialDatePicker()
73+
const picker = new MaterialDateTimePicker()
7474
.on('submit', (val) => {
7575
input.value = val.format("DD/MM/YYYY");
7676
});

dist/material-datetime-picker.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
.c-datepicker__header-date span {
105105
display: block;
106106
color: white;
107-
margin: 4px 0;
107+
margin: 0;
108108
transition: opacity 100ms ease-in-out; }
109109

110110
.c-datepicker__header-date__month {

dist/material-datetime-picker.js

Lines changed: 49 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/material-datetime-picker.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/material-datetime-picker.mjs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ var Events = function () {
210210
return Events;
211211
}();
212212

213+
var ESC_KEY = 27;
214+
213215
var prefix = 'c-datepicker';
214216
var defaults$$1 = function defaults$$1() {
215217
return {
@@ -310,18 +312,24 @@ var DateTimePicker = function (_Events) {
310312
// and deal with updating the view only).
311313
// For now this allows us to set the default time using the same quantize
312314
// rules as setting the date explicitly. Setting this.value meets setTime|Date's
313-
// expectation that we have a value, and `0` guarantees that we will detect
315+
// expectation that we have a value, and `0` guarantees that we will detect
314316
this.value = moment(0);
315317
this.setDate(this.options.default);
316318
this.setTime(this.options.default);
319+
} else {
320+
this.setDate(this.value);
321+
this.setTime(this.value);
317322
}
318323

319324
this.initializeRome(this.$('.' + this.options.styles.container), this.options.dateValidator);
325+
this._listenForCloseEvents();
326+
320327
this._show();
321328
}
322329
}, {
323330
key: 'close',
324331
value: function close() {
332+
this._stopListeningForCloseEvents();
325333
this._hide();
326334
}
327335
}, {
@@ -352,68 +360,91 @@ var DateTimePicker = function (_Events) {
352360
});
353361
return this;
354362
}
363+
}, {
364+
key: '_listenForCloseEvents',
365+
value: function _listenForCloseEvents() {
366+
var _this4 = this;
367+
368+
this._onWindowKeypress = function (e) {
369+
if (e.which === ESC_KEY) {
370+
_this4.close();
371+
}
372+
};
373+
374+
window.addEventListener("keydown", this._onWindowKeypress);
375+
}
376+
}, {
377+
key: '_stopListeningForCloseEvents',
378+
value: function _stopListeningForCloseEvents() {
379+
window.removeEventListener("keydown", this._onWindowKeypress);
380+
this._closeHandler = null;
381+
}
355382
}, {
356383
key: 'delegateEvents',
357384
value: function delegateEvents() {
358-
var _this4 = this;
385+
var _this5 = this;
359386

360387
this.$('.js-cancel').addEventListener('click', function () {
361-
return _this4.clickCancel();
388+
return _this5.clickCancel();
362389
}, false);
363390
this.$('.js-ok').addEventListener('click', function () {
364-
return _this4.clickSubmit();
391+
return _this5.clickSubmit();
365392
}, false);
366393

367394
this.$('.js-date-hours').addEventListener('click', function (e) {
368-
return _this4.showHourClock(e);
395+
return _this5.showHourClock(e);
369396
}, false);
370397
this.$('.js-date-minutes').addEventListener('click', function (e) {
371-
return _this4.showMinuteClock(e);
398+
return _this5.showMinuteClock(e);
372399
}, false);
373400

374401
this.$('.js-clock-hours').addEventListener('mouseleave', function (e) {
375-
return _this4.mouseOutHourClock(e);
402+
return _this5.mouseOutHourClock(e);
376403
}, false);
377404
this.$('.js-clock-hours .' + this.options.styles.clockNum).forEach(function (el) {
378405
el.addEventListener('click', function (e) {
379-
return _this4.clickClickHour(e);
406+
return _this5.clickClickHour(e).showMinuteClock();
380407
}, false);
381408
el.addEventListener('mouseenter', function (e) {
382-
return _this4.mouseInHourClock(e);
409+
return _this5.mouseInHourClock(e);
383410
}, false);
384411
});
385412

386413
this.$('.js-clock-minutes').addEventListener('mouseleave', function (e) {
387-
return _this4.mouseOutMinuteClock(e);
414+
return _this5.mouseOutMinuteClock(e);
388415
}, false);
389416
this.$('.js-clock-minutes .' + this.options.styles.clockNum).forEach(function (el) {
390417
el.addEventListener('click', function (e) {
391-
return _this4.clickClockMinute(e);
418+
return _this5.clickClockMinute(e);
392419
}, false);
393420
el.addEventListener('mouseenter', function (e) {
394-
return _this4.mouseInMinuteClock(e);
421+
return _this5.mouseInMinuteClock(e);
395422
}, false);
396423
});
397424

398425
this.$('.c-datepicker__clock--am').addEventListener('click', function (e) {
399-
return _this4.clickAm(e);
426+
return _this5.clickAm(e);
400427
}, false);
401428
this.$('.c-datepicker__clock--pm').addEventListener('click', function (e) {
402-
return _this4.clickPm(e);
429+
return _this5.clickPm(e);
403430
}, false);
404431

405432
this.$('.js-show-calendar').addEventListener('click', function (e) {
406-
return _this4.clickShowCalendar(e);
433+
return _this5.clickShowCalendar(e);
407434
}, false);
408435
this.$('.js-date-day').addEventListener('click', function (e) {
409-
return _this4.clickShowCalendar(e);
436+
return _this5.clickShowCalendar(e);
410437
}, false);
411438
this.$('.js-date-month').addEventListener('click', function (e) {
412-
return _this4.clickShowCalendar(e);
439+
return _this5.clickShowCalendar(e);
413440
}, false);
414441

415442
this.$('.js-show-clock').addEventListener('click', function (e) {
416-
return _this4.clickShowClock(e);
443+
return _this5.clickShowClock(e);
444+
}, false);
445+
446+
this.scrimEl.addEventListener('click', function () {
447+
return _this5.close();
417448
}, false);
418449

419450
return this;

dist/material-datetime-picker.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/.DS_Store

-6 KB
Binary file not shown.

lib/js/__tests__/index-test.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,45 @@ test("opening the picker ads backdrop and picker elements to the dom", () => {
1616

1717
const $backdrop = $(".c-scrim");
1818
const $picker = $(".c-datepicker");
19-
19+
2020
expect($picker).not.toBeNull();
2121
expect($backdrop).not.toBeNull();
2222
});
2323

2424
test("closing the picker removes elements from the dom", async () => {
25-
const picker = await openPicker()
25+
const picker = await openPicker();
2626
picker.close();
2727
await delay(300);
28-
28+
2929
const $backdrop = $(".c-scrim");
3030
const $picker = $(".c-datepicker");
3131

3232
expect($picker).toBeNull();
3333
expect($backdrop).toBeNull();
3434
});
3535

36+
test("the picker closes when the escape key is pressed", async () => {
37+
const picker = await openPicker();
38+
39+
const event = new window.KeyboardEvent('keydown', { which: 27, keyCode: 27 });
40+
window.dispatchEvent(event);
41+
42+
await delay(300);
43+
const $picker = $(".c-datepicker");
44+
expect($picker).toBeNull();
45+
});
46+
47+
test("the picker closes when the scrim element is clicked", async () => {
48+
const picker = await openPicker();
49+
50+
const event = new MouseEvent('click');
51+
$(".c-scrim").dispatchEvent(event);
52+
53+
await delay(300);
54+
const $picker = $(".c-datepicker");
55+
expect($picker).toBeNull();
56+
});
57+
3658
test("opening the picker with a default time", async () => {
3759
// time divides 5 minutes; set exactly
3860
const time = "2017-02-01T17:30:00.000Z";
@@ -126,4 +148,4 @@ test("picker#set quanitizes to the nearest 5 minutes", async () => {
126148
// test round up
127149
picker.set("2017-02-01T18:35:04.941Z");
128150
expect(picker.data().toISOString()).toEqual( "2017-02-01T18:35:00.000Z");
129-
})
151+
})

0 commit comments

Comments
 (0)