-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor(date-selector): Refactor DateSelector component #313
Conversation
bed5aa0
to
ef5a559
Compare
ef5a559
to
8b5f1e7
Compare
8b5f1e7
to
9eb6abb
Compare
Two things I noticed: You could set a Another question: this will break all our end to end tests? |
9eb6abb
to
106b0e3
Compare
@busypeoples Added the year only validation.
|
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.
Works pretty well!
I'm requesting changes mostly to use the input labels instead of the data-testid.
dayjs(date).isAfter(dateCalendarFromMonth) || | ||
dayjs(date).isBefore(dateCalendarToMonth) | ||
) { | ||
const selectedDate = dayjs(date).format(dateFormat); |
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.
It seems like we are not checking if dateFormat
is a valid date until the component performs an update.
Do you think we could fail earlier?
E.g. throw and exception during development if the dateFormat
is incorrect.
|
||
await user.type(getByTestId('date-selector-day'), '5'); | ||
await user.type(getByTestId('date-selector-month'), '7'); | ||
await user.type(getByTestId('date-selector-year'), '2023'); |
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.
To make sure we are not impacting accessibility, IMHO it'd be better if we stick to the actual input labels, and not rely on data-testid
.
Is there a reason to use data-testid
to target these inputs?
'data-testid': `date-selector-${key}`, | ||
className: styles[`${key}Input`], | ||
id: key, | ||
name: key, |
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.
How can we use this as uncontrolled component?
To give you more context, on the task engine we are adding a specific name and id to each input.
For example, a text input would have an id like this: input-f8556724-a703-455e-a6f5-16b0d16bb26d
But for the date input, we want the full date, so we are doing a tiny hack by using a hidden field with the full date.
I'm wondering if we should have such hidden field already inside the component instead of the individual name for each input.
Happy to discuss this a bit further. We don't need to change anything for this PR.
required: true, | ||
label: placeholders?.[key], | ||
placeholder: placeholders?.[`${key}Format` as FormatPlaceholder] ?? "", | ||
labelInsideInput: true, |
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.
Are we not allowing this to be configured via props?
What this PR does
This PR refactors the date selector component to have 3 text inputs instead of 3 select inputs.
By setting 3 inputs it means that keyboard/typing navigation also needs some custom adjustments:
when reaching the end of input, focus changes to next input:
when using right/left arrows, it is possible to navigate to next/previous inputs (like tab and shit+tab). if there is a value already, input value is selected
backspace, if current focused input is empty, goes to previous input:
if day is 4 or more focus changes to month input, if month is 2 or more focus changes to year input:
How to test?
Test visiting the story:
http://localhost:9009/?path=/docs/jsx-dateselector--date-selector-story
Before:
After:
Checklist:
Or give a reason why this does not apply:
Or give a reason why this does not apply:
Browser support
My code works in the following browsers: