-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Conversation
…ned when a day is picked
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.
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/DatePicker.svelte
Outdated
let dayOfMonth = value.getDate() | ||
$: dayOfMonth = value.getDate() | ||
let dayOfMonth = tmpPickerDate.getDate(); | ||
$: dayOfMonth = tmpPickerDate.getDate(); |
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 think we might want dayOfMonth
to be null
when value
is null
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 don't think it can ever be null currently because there is always a default date.
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.
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.
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.
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.
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.
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
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.
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?
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 don't think anything should be highlighted by default, really
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.
...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
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.
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.
Implemented on my nullable
branch
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.
Breaking change notes:
DatePicker
,DateInput
:value
is nowDate | null
DatePicker
,DateInput
:value
defaults tonull
DateInput
:value
becomesnull
when the input field is cleared
.gitignore
Outdated
@@ -2,3 +2,5 @@ | |||
/.svelte-kit | |||
/package | |||
/coverage | |||
/.idea/ |
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.
/.idea/ |
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.
Done on my nullable
branch
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
src/lib/DatePicker.svelte
Outdated
let shownDate = value ?? defaultDate | ||
$: shownDate = value ?? defaultDate |
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.
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
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.
Fixed this on my nullable
branch
Found a couple bugs:
|
^-- 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. |
Pushed them all into here. We should be pretty much good to go.
So right now with my change to not highlight any date, using the arrow keys will select a date relative to |
Resolved conflicts and updated the PR - we should be good to go but feel free to poke at it more. |
Thanks!! :D |
Creating new PR targeting your upstream repo instead of my forked repo - review changes applied. Will close my original local PR