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

ISSUE#1: Handle null dates #7

Merged
merged 29 commits into from
Feb 17, 2022
Merged

Conversation

mkelandis
Copy link
Contributor

Creating new PR targeting your upstream repo instead of my forked repo - review changes applied. Will close my original local PR

Copy link
Owner

@probablykasper probablykasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

I updated the CI to work on PRs, so you can see that there are TypeScript issues that need to be fixed (and formatting which just needs npm run format).

src/lib/DateInput.svelte Outdated Show resolved Hide resolved
src/lib/DateInput.svelte Outdated Show resolved Hide resolved
src/lib/DateInput.svelte Outdated Show resolved Hide resolved
Comment on lines 83 to 97
let dayOfMonth = value.getDate()
$: dayOfMonth = value.getDate()
let dayOfMonth = tmpPickerDate.getDate();
$: dayOfMonth = tmpPickerDate.getDate();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want dayOfMonth to be null when value is null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can ever be null currently because there is always a default date.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmpPickerDate can't, but value can be null. I was imagining that when DateInput is null, DatePicker should be null and as a result not have any date highlighted.

Right now, DatePicker starts as null but the defaultDate's dayOfMonth is highlighted, so to a user it looks like that's already selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO - until they click on a specific day the value should stay unassigned - otherwise as soon as they launch the picker the date will get assigned to the default without the user actually selecting a day as a side effect.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating dayOfMonth doesn't update the value, so that wouldn't happen. If dayOfMonth is null, we would make sure no date shows up as selected before the user actually selects a date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, DatePicker starts as null but the defaultDate's dayOfMonth is highlighted, so to a user it looks like that's already selected.

^-- Agree that this is still an issue. What do you think about having the picker show the default date in a lighter highlighted style - similar to the placeholder? Then when they select it it changes style to what you have now or something that clearly indicates the date is selected?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anything should be highlighted by default, really

Copy link
Contributor Author

@mkelandis mkelandis Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...so then the default date would effectively be a default month and year to start the picker with no day selected - i don't think it's being used for anything else at this point.

Not sure about the correct UX for this, but I searched for "w3c" and "date picker" and the first example shows the date highlighted in the picker before it's selected (and before it assigns the value):
https://www.w3.org/TR/wai-aria-practices/examples/dialog-modal/datepicker-dialog.html

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's pretty common to not have a date highlighted when no date is selected. Blueprint and Airbnb both do it.

If DatePicker uses a default value anyway, I don't think it would make sense to allow it to be null

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented on my nullable branch

src/lib/DatePicker.svelte Outdated Show resolved Hide resolved
src/routes/docs.md Outdated Show resolved Hide resolved
src/routes/docs.md Outdated Show resolved Hide resolved
Copy link
Owner

@probablykasper probablykasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change notes:

  • DatePicker, DateInput: value is now Date | null
  • DatePicker, DateInput: value defaults to null
  • DateInput: value becomes null when the input field is cleared

.gitignore Outdated
@@ -2,3 +2,5 @@
/.svelte-kit
/package
/coverage
/.idea/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/.idea/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done on my nullable branch

src/lib/DateInput.svelte Outdated Show resolved Hide resolved
src/lib/DatePicker.svelte Outdated Show resolved Hide resolved
src/lib/parse.ts Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #7 (1164753) into master (bec526b) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   98.03%   98.05%   +0.01%     
==========================================
  Files           4        4              
  Lines         153      154       +1     
  Branches       41       42       +1     
==========================================
+ Hits          150      151       +1     
  Misses          3        3              
Impacted Files Coverage Δ
src/lib/date-utils.ts 100.00% <100.00%> (ø)
src/lib/parse.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bec526b...1164753. Read the comment docs.

Comment on lines 25 to 26
let shownDate = value ?? defaultDate
$: shownDate = value ?? defaultDate
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let shownDate = value ?? defaultDate
$: shownDate = value ?? defaultDate
/** The date shown in the popup, for when `value` is null */
let shownDate = value ?? defaultDate
$: if (value) shownDate = value

We shouldn't reset the shownDate to default when the value is set to null

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this on my nullable branch

@probablykasper
Copy link
Owner

Found a couple bugs:

  1. If a date is selected, and you delete all text at once, invalid stays as false. However, if you delete it one character at a time, invalid is true.

  2. When the datepcker is focused and the value is null, using the arrow keys does not select a new value (you can focus the datepicker by clicking somewhere there is no button)

@mkelandis
Copy link
Contributor Author

When the datepicker is focused and the value is null, using the arrow keys does not select a new value

^-- If we decide to hide the default day in the picker per the earlier suggestion this issue goes away (I think). Right now I don't have a strong opinion about it. For this PR I will see if we can get the arrow keys to select the value.

Will try to address both of these shortly. Also feel free to put up piggy back prs with your suggested changes and I can just merge them into mine.

@probablykasper
Copy link
Owner

Also feel free to put up piggy back prs with your suggested changes and I can just merge them into mine.

Pushed them all into here. We should be pretty much good to go.

If we decide to hide the default day in the picker per the earlier suggestion this issue goes away (I think)

So right now with my change to not highlight any date, using the arrow keys will select a date relative to shownDate (even when no date is highlighted). I think it's nice for them to select something so that you can still select dates via keyboard. Maybe it would be better if it selects from an edge (e.g LeftArrow selects top-right value), or relative to the current date, but I'm fine with how it is now either way.

@mkelandis
Copy link
Contributor Author

Resolved conflicts and updated the PR - we should be good to go but feel free to poke at it more.

@probablykasper
Copy link
Owner

Thanks!! :D

@probablykasper probablykasper merged commit 876723c into probablykasper:master Feb 17, 2022
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.

None yet

3 participants