onKeyup(ev) { if (Key.isNot(ev, Keycodes.ESC, Keycodes.LEFT, Keycodes.RIGHT, Keycodes.UP, Keycodes.DOWN, Keycodes.SPACE, Keycodes.ENTER, Keycodes.TAB)) // This is called when someone is typing into the field, therefore try to send the value to update // but do so without erroring in case parse is bad. try { this.dp.update() } catch (error) { // eslint-disable-line no-empty } }
onKeydown(ev) { if (!this.dp.isShowing()) { if (Key.is(ev, Keycodes.DOWN, Keycodes.ESC)) { // allow down to re-show picker this.dp.show() ev.stopPropagation() } return } switch (Key.toCode(ev)) { case Keycodes.ESC: this.popView(ev) break case Keycodes.ENTER: case Keycodes.TAB: this.acceptDate(ev) if (Key.is(ev, Keycodes.TAB)) { this.dp.hide() } break case Keycodes.LEFT: case Keycodes.UP: case Keycodes.RIGHT: case Keycodes.DOWN: { let focusDate = this.lastKeyboardFocusDate || this.dp.dates.last() || this.dp.viewDate if (!this.config.keyboard.navigation || this.config.daysOfWeek.disabled.length === 7) { break } let direction = Key.is(ev, Keycodes.LEFT, Keycodes.UP) ? -1 : 1 let unit if (this.dp.view === View.DAYS) { if (ev.ctrlKey) { unit = Unit.YEAR } else if (ev.shiftKey) { unit = Unit.MONTH } else if (Key.is(ev, Keycodes.LEFT, Keycodes.RIGHT)) { unit = Unit.DAY } else if (!this.dp.weekOfDateIsDisabled(focusDate)) { unit = Unit.WEEK } } else if (this.dp.view === View.MONTHS) { if (Key.is(ev, Keycodes.UP, Keycodes.DOWN)) { direction = direction * 4 } unit = Unit.MONTH } else if (this.dp.view === View.YEARS) { if (Key.is(ev, Keycodes.UP, Keycodes.DOWN)) { direction = direction * 4 } unit = Unit.YEAR } // now move the available date and render (highlight the moved date) if (unit) { this.lastKeyboardFocusDate = this.dp.viewDate = this.dp.moveAvailableDate(focusDate, direction, unit) this.renderer.render() this.trigger(Event[`${unit.toUpperCase()}_CHANGE`]) ev.preventDefault() } break } } }