-
Notifications
You must be signed in to change notification settings - Fork 240
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
Merged
kentcdodds
merged 4 commits into
testing-library:master
from
gndelia:gndelia/feature/time-support
Dec 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thetime
input here: https://codesandbox.io/s/user-event-playground-eo909?file=/index.htmlThat doesn't end up firing a change event because I need to type in
a
(for AM) orp
(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 theinput.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.
In my case trying with chrome I don't have to type
a
orp
. I guess you're right, it depends on the browser or user-agent, or something else.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 senseIf 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 scenariosThere 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.
How about this? https://testing-playground.com/gist/7b5d922642a0a1814209c81db6867b59/1b0329837c8afa1d5e972e219ed65ba041f69c82
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