-
Notifications
You must be signed in to change notification settings - Fork 128
Adds character counter to TextArea and TextField components #3785
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 8dfc244 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| <%= builder.text_area(@input.name, **@input.input_arguments) %> | ||
| <% end %> | ||
| <% if @input.character_limit? %> | ||
| <%= content_tag(:div, **character_limit_validation_arguments, data: { target: "primer-text-area.validationElement" }) do %> |
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.
We need to define validation because an error needs to appear as a user is making updates. My understanding is that current validation is designed to only show after form submission. Let me know if there is a better way to do this, though!
| <% if @input.character_limit? %> | ||
| <%= content_tag(:div, **character_limit_validation_arguments, data: { target: "primer-text-area.validationElement" }) do %> | ||
| <span class="FormControl-inlineValidation--visual"><%= render(Primer::Beta::Octicon.new(icon: :"alert-fill", size: :xsmall, aria: { hidden: true })) %></span> | ||
| <span data-target="primer-text-area.validationMessageElement"></span> |
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.
|
FYI we have similar but different patterns implemented piecemeal in other places. I've done it so that the message is I like it a little better than stacking the count with another error and a caption — that's just a lot of text. |
|
@dylanatsmith What if instead of adding a new validation message, when a user types over the limit, the text changes to red and there's an error icon next to the "x characters over" message? We can still keep the error styling (red border) around the textarea. I am thinking from an accessibility perspective too, since the "x characters over" text is already read to screen reader users, adding an "error" to the message should suffice. |
|
I am making some updates to this so it might be best to hold off on reviewing; I will ping you all when it's ready again! |
|
@dylanatsmith an update for you :) This is what it'd look like when you have an error message and you've exceeded the character limit.
|
|
@jonrohan @dylanatsmith Ok this is ready again for review, PR description, video, & screenshots have been updated! |
|
@lukasoppermann For design input from Primer 👀 |


What are you trying to accomplish?
Adds character count functionality to the TextArea and TextField components.
Note: I have an open question w/our accessibility experts about the caption announcing twice on NVDA and whether or not this is expected behavior w/NVDA.
Screenshots
Below is a video showcasing that TextArea and TextField components have an optional
character_limitthat can be passed in as an argument. When a user types, the field is updated with how many characters are left / how many are over. When a user exceeds the limit, the character count text changes to red and an error icon prepends the text.There is also an aria-live region that updates after a slight delay (500ms) when a user finishes typing. This accurately tells screen reader users how many characters they have left / are over, as well as when the input is invalid if they have typed too many characters.
ominous-space-lamp-rrp7x5r5jg525www-4000.app.github.dev_lookbook_inspect_primer_alpha_text_area_playground_character_limit.10.validation_message.-.10.December.2025.mp4
Integration
No - users can migrate to this new API once it's finished but nothing needs to be done in dotcom.
List the issues that this change affects.
Related to https://github.com/github/primer/issues/5937.
Risk Assessment
I chose low risk since we are only adding to the API.
What approach did you choose and why?
Some decisions made w/accessibility in mind:
Anything you want to highlight for special attention from reviewers?
Accessibility
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.