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
feat(type): add time input support #502
feat(type): add time input support #502
Conversation
Codecov Report
@@ Coverage Diff @@
## master #502 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 615 664 +49
Branches 200 211 +11
=========================================
+ Hits 615 664 +49
Continue to review full report at Codecov.
|
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 for your work on this! Just one thing.
Also, let's make sure we add docs :)
src/__tests__/type.js
Outdated
|
||
test('can type more a number higher than 60 minutes into an input `time` and they are converted into 59 minutes', () => { | ||
const {element, getEventSnapshot} = setup('<input type="time" />') | ||
userEvent.type(element, '2390') |
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 I type 2390
in the time
input here: https://codesandbox.io/s/user-event-playground-eo909?file=/index.html
That doesn't end up firing a change event because I need to type in a
(for AM) or p
(for PM). It's possible that this is a user-agent thing, in which case I think the implementation here is fine. In any case, we'll want to make sure we document how a time is intended to be entered for a given time value.
I'm thinking that rather than having them provide 0105
we should have them pass the value they want the input.value
to be when the typing is complete. So that would be: userEvent.type(element, '01:05')
. I think that would be more intuitive. We'd just need to make sure we handle this internally because the end user wouldn't actually bother typing the :
I think.
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.
That doesn't end up firing a change event because I need to type in a (for AM) or p (for PM). It's possible that this is a user-agent thing, in which case I think the implementation here is fine. In any case, we'll want to make sure we document how a time is intended to be entered for a given time value.
In my case trying with chrome I don't have to type a
or p
. I guess you're right, it depends on the browser or user-agent, or something else.
I'm thinking that rather than having them provide 0105 we should have them pass the value they want the input.value to be when the typing is complete. So that would be: userEvent.type(element, '01:05'). I think that would be more intuitive. We'd just need to make sure we handle this internally because the end user wouldn't actually bother typing the : I think.
technically speaking, all the non-digit characters are ignored, as that's what happens when using the <input type="time" />
. So I could rewrite the tests to use :
and they will work with the current implementation (and the docs could be with that). What do you think?
if that's enough as the request, I could rewrite the tests and the docs (yet to be added) to show the examples using :
. That's probably better in terms of DX, but as you say the user would never type :
. Working without :
is an extra in that sense
If you think it is better to change the implementation to just split hours and minutes by :
, then I can do it; in this scenario, the user would always have to type :
or it wouldn't work (with the current approach, both works). and I'd have to validate both separatedly
(I also went without :
probably biased by the example in the ticket, which was not using it).
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.
That all sounds great. Thank you. I think having the :
in the docs would be preferable/sensible. And having at least one test that uses :
as well as at least one that does not would be good.
Thanks for all of this work!
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.
changes applied in 8333075
-
updated docs to have an example of using
<input type="time />
. My main doubt is that there are no roles associated to this type of input, so the only way to query it was with adata-testid
. Should I use another option? -
I updated all tests to use
01:05
, and also added one without the:
to verify it works in both scenarios
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 clarify, I tried with labels in testing-playground but it did not work either - that's why I went for data-testid
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.
I swear I tried it and I was getting an error 🤔 but 🤷
updated in 774a030
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 super. Just a few small things and then we can get this merged. Thanks!
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.
Well done 👏
@all-contributors please add @gndelia for code, tests, and docs |
I've put up a pull request to add @gndelia! 🎉 |
Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the |
🎉 This PR is included in version 12.4.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
What: Adding support for
<input type="time" />
. Check #484Why: That type of input does not work. It does with
fireEvent
, thoughHow: Adding the functionality for it. I had to interpret the typed characters to hours and minutes, adding the
:
between both.Checklist: