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
[TextField / Labelled] Add character count #709
Conversation
I'm also in favor of that positioning, @solonaarmstrong. cc: @sarahill to confirm |
@solonaarmstrong @danrosenthal I also agree and think that it looks better in that position. The one reason, that came up in the issue, for putting it below was that if the textfield had a lot of text in it the user might not be able to see the count as they type if it was at the top of the field. Its probably a rare case but just thought I would bring that up again to be included in the consideration. |
I think that's an acceptable limitation. |
I like @solonaarmstrong suggestion for placement. Couple questions/thoughts:
|
@sarahill This is how it currently behaves on small screens in the admin (for SEO, as an example). It simply needs to stack. |
5ed6d90
to
ba594cd
Compare
@danrosenthal @solonaarmstrong I made the changes to the placement etc. One thing that I ran into is that the placement of the label action gets a little weird when also showing the character count. Currently this is what I have it doing when both are present: Its probably a super rare case to have all three... label action will still be on the far right if the |
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 feeling like a really strong step in the right direction, but I feel that the separation of concerns is wrong here. The character count feels like it should be the concern of the TextField
component itself, but in this implementation the Labelled
component is doing most of the work. In my opinion, the generation of the characterCount
markup should be the concern of the TextField
itself, and should just be passed as a ReactNode to the Labelled
component, which should not really care what it is, and only should be concerned with where to render it.
What do you think about doing all the work in the TextField
component, and then passing it to the action
prop of Labelled
? Then Labelled
could check if it received an object or a ReactNode
as an action, and render it accordingly. My only hesitation here is that it would feel a bit unnatural to pass something that wasn't an Action
to the action
prop, but I think I'm okay with that. It would also solve your display problem of figuring out whether or not to render the Action
, as the Labelled
could only take one or the other.
Thoughts about this approach?
@danrosenthal I definitely agree with you. It felt weird putting all the logic in Labelled. I like the idea of passing it through the action prop, my only concern is that you will then not be able to have both at the same time. I know for my project that isn't a concern. I guess if it becomes a problem in the future that can be addressed then? My main question then is if someone passes a I am also worried about people trying to do an action and a character count and wondering why one of them doesn't show up (But maybe just saying why in the docs is enough?) |
8703e1d
to
b4c1059
Compare
b4c1059
to
9932e19
Compare
9932e19
to
0858561
Compare
0858561
to
539c0dd
Compare
539c0dd
to
1420918
Compare
It ended up making more sense to provide a fixed line-height to the CharacterCount instead of shifting around the margins if it's a multiline text field. I believe we still need the I believe this should be good to go pending the two ✅ and someone approving percy. @solonaarmstrong and @dpersing could you please take another look? |
Hi @emarchak! It looks like the
I'm thinking that "X of Y characters used" would make more sense with the visual? |
1420918
to
b8d6e8e
Compare
Fixed! |
b8d6e8e
to
447bd0b
Compare
|
||
"TextField": { | ||
"characterCount": "{count} characters", | ||
"characterCountWithMaxLength": "{count} of {limit} characters used" |
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 contribution to Polaris React! |
I'm using bellow code example but
|
@fchienvuhoang I just tried and I see it in there in v3.9.0. |
WHY are these changes introduced?
Resolves #491
TextField lacks the ability to display the remaining characters available when the TextField has a max character length. This PR adds that ability.
WHAT is this pull request doing?
Adds in the prop
showCharacterCount
to TextField to enable the displaying of the remaining character count.The
Labelled
component will then display the number of characters out of the total allowed characters that have been inputted into the TextField.One item of note is that things can get a little busy as can be seen below:
@dpersing was giving insight into this on the issue.
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist