Skip to content

Commit 6dfaa91

Browse files
author
Nathan Reyes
committed
Change default value for 'datePickerUpdateOnInputKeyup'. Add escape key handling for 'v-date-picker'.
1 parent 9e97e86 commit 6dfaa91

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
## Improvements
1414
### `v-date-picker`
15+
* Improve input key handing, specifically for `enter` and `esc` keys
1516
* Added `update-on-input-keyup` prop to update picker selection on every `keyup` event.
1617
* Custom slot method `updateValue` can now accept options as the second parameter. Closes #118.
1718

1819
| Property | Description | Default Value |
1920
| -------- | ----------- | ------------- |
20-
| `formatInput` | If new value is valid, date picker should reformat the `inputValue`. | `true` |
21+
| `formatInput` | If new value is valid, date picker should reformat the `inputValue` (based on `formats.input`). | `true` |
2122
| `hidePopover` | If new valud is valid, date picker should hide popover. | `!popoverKeepVisibleOnInput` |
2223

2324
```html

src/components/DatePicker.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,21 @@ export default {
416416
}
417417
},
418418
inputChange() {
419+
// Enter key, blur or other change events
419420
this.updateValue(this.inputValue, {
420421
formatInput: true,
421422
hidePopover: false,
422423
});
423424
},
424425
inputKeyup(e) {
425-
if (e.keyCode !== 13 && this.updateOnInputKeyup) {
426+
// Escape key
427+
if (e.keyCode === 27) {
428+
this.updateValue(this.value, {
429+
formatInput: true,
430+
hidePopover: true,
431+
});
432+
// All other keys
433+
} else if (e.keyCode !== 13 && this.updateOnInputKeyup) {
426434
this.updateValue(this.inputValue, {
427435
formatInput: false,
428436
hidePopover: false,
@@ -460,7 +468,7 @@ export default {
460468
this.$emit('input', filteredValue);
461469
} else {
462470
if (formatInput) this.formatInput();
463-
if (hidePopover) this.popoverForceHidden = true;
471+
if (hidePopover) this.hidePopover();
464472
}
465473
},
466474
formatInput() {
@@ -471,7 +479,7 @@ export default {
471479
hidePopover() {
472480
setTimeout(() => {
473481
this.popoverForceHidden = true;
474-
}, 300);
482+
}, 200);
475483
},
476484
},
477485
};

src/utils/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const defaults = {
4141
placeholder: `${format} - ${format}`,
4242
}),
4343
}),
44-
datePickerUpdateOnInputKeyup: true,
44+
datePickerUpdateOnInputKeyup: false,
4545
datePickerTintColor: '#66B3CC',
4646
datePickerShowCaps: false,
4747
datePickerShowDayPopover: true,

0 commit comments

Comments
 (0)