diff --git a/src/DatetimePopup.vue b/src/DatetimePopup.vue
index 7daa177..b9b4116 100644
--- a/src/DatetimePopup.vue
+++ b/src/DatetimePopup.vue
@@ -43,6 +43,7 @@ import DatetimeTimePicker from './DatetimeTimePicker'
import DatetimeYearPicker from './DatetimeYearPicker'
const KEY_TAB = 9
+const KEY_ENTER = 13
const KEY_ESC = 27
export default {
@@ -206,8 +207,15 @@ export default {
}
},
onKeyDown (event) {
- if (event.keyCode === KEY_ESC || event.keyCode === KEY_TAB) {
- this.cancel()
+ switch (event.keyCode) {
+ case KEY_ESC:
+ case KEY_TAB:
+ this.cancel()
+ break
+
+ case KEY_ENTER:
+ this.nextStep()
+ break
}
}
}
diff --git a/test/specs/DatetimePopup.spec.js b/test/specs/DatetimePopup.spec.js
index 9648fb5..d5ff66f 100644
--- a/test/specs/DatetimePopup.spec.js
+++ b/test/specs/DatetimePopup.spec.js
@@ -315,6 +315,32 @@ describe('DatetimePopup.vue', function () {
})
})
+ it('should emit confirm event on key down ENTER', function (done) {
+ const vm = createVM(this,
+ ``,
+ {
+ components: { DatetimePopup },
+ data () {
+ return {
+ datetime: LuxonDatetime.local(),
+ spy: sinon.spy()
+ }
+ }
+ })
+
+ expect(vm.spy).to.have.not.been.called
+
+ const event = document.createEvent('Event')
+ event.keyCode = 13
+ event.initEvent('keydown')
+ document.dispatchEvent(event)
+
+ vm.$nextTick(() => {
+ expect(vm.spy).to.have.been.calledOnce
+ done()
+ })
+ })
+
it('should emit cancel event on cancel', function () {
const vm = createVM(this,
``,