[v10] Add character count countType: "words" option using Intl.Segmenter#1899
Merged
Conversation
4933601 to
e51d1a4
Compare
6b80700 to
07676d2
Compare
e51d1a4 to
f61329c
Compare
07676d2 to
649b198
Compare
f61329c to
7fc007c
Compare
649b198 to
e76c2e7
Compare
8008c6a to
9e21bc3
Compare
6c80311 to
3290d27
Compare
9e21bc3 to
ea4e0f4
Compare
3290d27 to
9492e12
Compare
ea4e0f4 to
25511df
Compare
9492e12 to
e93b9da
Compare
25511df to
fa996f5
Compare
fa996f5 to
5c1cbb6
Compare
1becd9a to
a6d1b7b
Compare
Contributor
Author
|
@anandamaryon1 I've added three changelog entries for:
If you can check please? 🙏 |
a6d1b7b to
00aafdb
Compare
Unless the (deprecated) `maxwords` option is used
…nter Unless the (deprecated) `maxwords` option is used
Users may provide their own fallback without needing Intl.Segmenter
00aafdb to
614cba9
Compare
anandamaryon1
approved these changes
Jun 1, 2026
614cba9 to
9e0feef
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR extends #1895 to add character count support for
countType: "words"using Intl.Segmenter{{ characterCount({ label: { text: "Can you provide more detail?" }, name: "more-detail", - maxwords: 200 + maxlength: 200, + countType: "words" }) }}Issues with separator regex
The existing word count behaviour uses
/\S+/gto count all consecutive non-whitespace charactersBut consider this phrase where hyphens and em-dashes are used as separators:
It matches only 3 words currently:
Yet using the segmenter with
granularity: "word"it matches 6 words:To solve this, but avoid breaking changes:
countType: "wordswill use Intl.Segmenter in modern browsersmaxwords(deprecated) will use the existing word count behaviourBut what about older browsers that lack Intl.Segmenter support?
They'll fall back to the static non-JS text customisable via
textareaDescriptionText, for example:Checklist