-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
close the calendar on input blur #485
close the calendar on input blur #485
Conversation
10b01bc
to
d54c916
Compare
d54c916
to
251d865
Compare
Change the calendar close implementation. Remove document click handler (which may fail if click propagation is stopped by another handler). Use input blur event instead. Use @mousedown.prevent on calendar containers to prevent change in focus from the input to the calendar.
5d851e1
to
630c08d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice @mnich0ls - I didn't know about using mousedown preventDefault to keep the focus on the input.
I've just left a minor comment about my preference for guards and there's just one failing test - more than happy to merge once those are addressed.
@@ -32,19 +32,17 @@ describe('DateInput', () => { | |||
it('emits the date when typed', () => { | |||
const input = wrapper.find('input') | |||
wrapper.vm.input.value = '2018-04-24' | |||
input.trigger('keypress') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this line makes the test fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I'm getting different tests results locally. This passes for me and I added this line because my tests results were showing that line 103 of DateInput.vue was uncovered. Any pointers how ensuring I get the same results as travis-ci?
src/components/DateInput.vue
Outdated
} | ||
if (isNaN(Date.parse(this.input.value))) { | ||
this.clearDate() | ||
if (this.typedDate && this.typeable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep the nesting level lower and return if we don't pass this.
I find this style much easier to read and reason about.
Additionally typedDate
should never be truthy if typeable
is false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.
if (!isNaN(typedDate)) { | ||
this.typedDate = this.input.value | ||
this.$emit('typedDate', new Date(this.typedDate)) | ||
if (this.typeable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is false, I'd prefer to return here.
@@ -1,5 +1,5 @@ | |||
<template> | |||
<div :class="[calendarClass, 'vdp-datepicker__calendar']" v-show="showDayView" :style="calendarStyle"> | |||
<div :class="[calendarClass, 'vdp-datepicker__calendar']" v-show="showDayView" :style="calendarStyle" @mousedown.prevent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -43,7 +43,7 @@ describe('Datepicker mounted', () => { | |||
wrapper.vm.setValue() | |||
expect(wrapper.vm.selectedDate).toEqual(null) | |||
const pageDate = new Date(wrapper.vm.pageDate) | |||
expect(pageDate.getYear()).toEqual(now.getYear()) | |||
expect(pageDate.getFullYear()).toEqual(now.getFullYear()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 getYear
is so wonky :/
simplify nested if statement in inputBlurred()
Thanks for reviewing! I pushed the changes minus the failing test. I can just remove the line that seems to be causing travis-ci to fail? I wish I could reproduce it locally. |
remove call to trigger keypress on input that causes test to fail.
Weirdly if you trigger the keypress to after the keyup it works...
|
complete code coverage of DateInput with additional test in typedDates.spec.js to ensure input allows keyboard input when configured accordingly.
Thanks! Added the additional test to complete test coverage. |
Good job @mnich0ls thanks! |
Available as a minor bump in v1.2.0 |
👍 |
Change the calendar close implementation.
Remove document click handler (which may fail if click propagation is stopped by another handler).
Use input blur event instead.
Use @mousedown.prevent on calendar containers to prevent change in focus from the input to the calendar.
Closes #484