Skip to content
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

Merged
merged 4 commits into from
May 11, 2018

Conversation

mnich0ls
Copy link
Contributor

@mnich0ls mnich0ls commented May 9, 2018

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

@mnich0ls mnich0ls changed the title close the calendar in input blur close the calendar on input blur May 9, 2018
@coveralls
Copy link

coveralls commented May 9, 2018

Coverage Status

Coverage increased (+0.3%) to 100.0% when pulling e0fd0fc on mnich0ls:close-calendar-bug-fix into 3f568ff on charliekassel:master.

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.
Copy link
Owner

@charliekassel charliekassel left a 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')
Copy link
Owner

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

Copy link
Contributor Author

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?

}
if (isNaN(Date.parse(this.input.value))) {
this.clearDate()
if (this.typedDate && this.typeable) {
Copy link
Owner

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.

Copy link
Contributor Author

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) {
Copy link
Owner

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>
Copy link
Owner

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())
Copy link
Owner

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()
@mnich0ls
Copy link
Contributor Author

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.
@mnich0ls
Copy link
Contributor Author

mnich0ls commented May 10, 2018

Here's what I get locally when I remove input.trigger('keypress') (ah, I see travis gets the same result. The test doesn't fail for me locally and I don't get the warning about the uncovered line with input.trigger('keypress'))

screen shot 2018-05-10 at 9 56 09 am

@charliekassel
Copy link
Owner

Weirdly if you trigger the keypress to after the keyup it works...
I think we can add this unit test to cover that line

it('allows typing', () => {
    wrapper.setProps({typeable: true})
    expect(wrapper.vm.allowTyping()).toEqual(true)
    wrapper.setProps({typeable: false})
    expect(wrapper.vm.allowTyping({preventDefault: () => {}})).toEqual(false)
  })

complete code coverage of DateInput with additional test in typedDates.spec.js to ensure input allows keyboard input when configured accordingly.
@mnich0ls
Copy link
Contributor Author

Thanks! Added the additional test to complete test coverage.

@charliekassel
Copy link
Owner

Good job @mnich0ls thanks!

@charliekassel charliekassel merged commit 1704388 into charliekassel:master May 11, 2018
@charliekassel
Copy link
Owner

Available as a minor bump in v1.2.0

@mnich0ls
Copy link
Contributor Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calendar popup does not close if click propagation is stopped
3 participants