An open source design system that's fully customizable and agent ready
TypeScript
fix(TextArea): the character counter comes from one catalog message (#9025)
Cindy Zhang64caf1dd0a7f
diff --git a/.changeset/textarea-counter-i18n.md b/.changeset/textarea-counter-i18n.mdnew file mode 100644index 0000000000..a87875f0fc--- /dev/null+++ b/.changeset/textarea-counter-i18n.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] TextArea: the `maxLength` character counter now comes from one catalog message (`@astryx.textArea.counter`), so its numbers use the locale's number format and translators can change the order or separator. In English a limit of 1,000 or more now shows grouped digits (`62/2,000` instead of `62/2000`).++@cixzhangdiff --git a/packages/core/locales/en.json b/packages/core/locales/en.jsonindex 6baace85a3..411102378d 100644--- a/packages/core/locales/en.json+++ b/packages/core/locales/en.json@@ -1567,6 +1567,10 @@"defaultMessage": "Expand all rows","description": "Aria label for the Table tree-data header toggle when rows are collapsed and clicking it expands them."},+ "@astryx.textArea.counter": {+ "defaultMessage": "{count, number}/{limit, number}",+ "description": "Visible character counter at the bottom of a TextArea that has a character limit, for example `62/2,000`. `{count}` is the characters typed so far and `{limit}` the limit; keep both numbers and reorder or change the separator if your language needs to."+ },"@astryx.textArea.charactersRemaining": {"defaultMessage": "{count, number} {count, plural, one {character} other {characters}} remaining","description": "Screen-reader-only announcement of how many characters the user can still type before hitting a TextArea's maxLength. Announced politely as the count nears the limit. `{count}` is the number remaining — example: `12 characters remaining`."diff --git a/packages/core/src/TextArea/TextArea.spec.md b/packages/core/src/TextArea/TextArea.spec.mdindex 9e43c06bb1..9fdb831e20 100644--- a/packages/core/src/TextArea/TextArea.spec.md+++ b/packages/core/src/TextArea/TextArea.spec.md@@ -52,15 +52,15 @@ system_specs: [spec:AST-085, spec:AST-086]## Contract at a glance-| Area | Contract |-| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Public contract | None changes. TextArea is a controlled multi-line field with Field props, `rows`, size, status, start icon, `maxLength` counter, `onChange`, `changeAction`, `isLoading`, disabled and read-only states, and the input-family part props. |-| Behavior | Typing calls `onChange`, then an optional `changeAction` with an optimistic value and one busy Spinner. `maxLength` adds a visual character counter that warns but never blocks typing. |-| End-user impact | People write longer text with a live count that is announced only when they near or pass the limit. Keyboard and screen-reader users can reach a disabled field and its reason. An error without a message has no text. |-| Builder impact | None. |-| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. Attached status on a tall surface, dropped grouped container props, text under the counter, counter text outside the catalog, an error without text, and a color-only `detached` status are listed under Current-state impact. |-| Review checks | Reject a counter that truncates input or counts code units, an announcement on every keystroke, text that runs under the icons or counter, a disabled field that leaves the tab order or submits, or root styling props. |-| Governing rules | `family:input-fields` FR4–FR6, FR8–FR10, AV3; `spec:AST-085` FR1–FR3, FR6; `spec:AST-086` FR8; `architecture:component-theming-surface`. |+| Area | Contract |+| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |+| Public contract | None changes. TextArea is a controlled multi-line field with Field props, `rows`, size, status, start icon, `maxLength` counter, `onChange`, `changeAction`, `isLoading`, disabled and read-only states, and the input-family part props. |+| Behavior | Typing calls `onChange`, then an optional `changeAction` with an optimistic value and one busy Spinner. `maxLength` adds a visual character counter that warns but never blocks typing. |+| End-user impact | People write longer text with a live count that is announced only when they near or pass the limit. Keyboard and screen-reader users can reach a disabled field and its reason. An error without a message has no text. |+| Builder impact | None. |+| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. Attached status on a tall surface, dropped grouped container props, text under the counter, an error without text, and a color-only `detached` status are listed under Current-state impact. |+| Review checks | Reject a counter that truncates input or counts code units, an announcement on every keystroke, text that runs under the icons or counter, a disabled field that leaves the tab order or submits, or root styling props. |+| Governing rules | `family:input-fields` FR4–FR6, FR8–FR10, AV3; `spec:AST-085` FR1–FR3, FR6; `spec:AST-086` FR8; `architecture:component-theming-surface`. |This table is a review projection; the body below is authoritative.@@ -128,7 +128,7 @@ Consumer migration instructions belong in consumer docs and release notes.| FR2 | The input container carries `text-area` with `data-size`, `data-status`, `data-disabled`, and `data-readonly`; the textarea carries `text-area-control`; the counter carries `text-area-counter`. Placeholder text is part of the textarea; the over-limit glyph is part of the counter. | `architecture:component-theming-surface`; current source and tests || FR3 | The textarea shows `rows` lines (default 3), resizes only vertically, and uses body text, floored at 16 CSS px only on the iOS touch path. `lg` adds block padding; `sm` and `md` share the default inset. | `family:input-fields` FR9, AV3; current source and tests || FR4 | Editing calls `onChange(value, event)`; unless that call prevents default, `changeAction(value, event)` then runs in a transition and the field shows the proposed value while the Action is pending, and `value` once it settles. While `isLoading` or while the shown value differs from `value`, the textarea sets `aria-busy`, a decorative Spinner shows, and the busy start is announced once. | `family:input-fields` FR5, FR6; `spec:AST-086` FR8; current tests |-| FR5 | With `maxLength`, a counter showing the character count and the limit renders at the container's bottom end and describes the textarea. It counts user-perceived characters, so a multi-code-point emoji counts once. It never sets the native `maxLength` and never blocks typing. Over the limit it turns the error color, adds a decorative warning icon, and sets `aria-invalid`. The counter text MUST come from one catalog message (`architecture:internationalization` INV1a). Implementation gap: it is assembled in code as count, slash, and limit. | Current tests; `architecture:internationalization` INV1a |+| FR5 | With `maxLength`, a counter showing the character count and the limit renders at the container's bottom end and describes the textarea. It counts user-perceived characters, so a multi-code-point emoji counts once. It never sets the native `maxLength` and never blocks typing. Over the limit it turns the error color, adds a decorative warning icon, and sets `aria-invalid`. The counter text MUST come from one catalog message (`architecture:internationalization` INV1a), with both numbers in the locale's number format. | Current tests; `architecture:internationalization` INV1a || FR6 | Counter announcements happen when an edit lands in a different zone than the previous edit: entering the last 20% of the limit announces the remaining characters politely; exceeding the limit announces the overage assertively; moving back under announces nothing. Zone tracking starts unset, so the first edit after mount announces the near or over zone it lands in, even when the mounted value was already there. | Current tests || FR7 | The start icon renders at the top start, and the Spinner and on-field status icon at the top end; the textarea reserves inline padding for each one that renders (more when both end items show) and bottom padding for the counter, so text never runs under them; the counter's bottom padding clears text only at the end of the scroll range. Implementation gap: with a value longer than `rows`, the last visible line paints under the counter unless the field is scrolled to the end. A detached status reserves no end space because it renders no on-field icon. | `family:input-fields` FR2; current source and tests || FR8 | A status paints the status border; `error` sets `aria-invalid`. The on-field status icon shows for `attached` and `tooltip` placement; a `detached` status shows its glyph only in the message box, which renders only with a message. The message renders through Field in the chosen placement. Every status MUST show a cue other than color (WCAG 2.2 1.4.1), and an error MUST be identified in text (WCAG 2.2 3.3.1). Implementation gap: TextArea offers `attached` placement, as its default and explicitly, although `family:input-fields` FR8 and AV6 allow `attached` only on a fixed-height control; an error status may have no message; and a `detached` status without a message shows only the colored border. | `family:input-fields` FR8; current tests |@@ -276,9 +276,6 @@ above match the current Field, FieldStatus, Icon, Spinner, and Tooltip targets.FR8 and AV6 allow `attached` only on a fixed-height control.- **Grouped container props (FR12).** Inside InputGroup, TextArea still rendersits Field box but drops `container*` props, warning that no Field box renders.-- **Counter text (FR5).** The counter's count-and-limit text is assembled in- code rather than from one catalog message, against- `architecture:internationalization` INV1a.- **Text under the counter (FR7).** With a value longer than `rows`, the lastvisible line paints under the counter unless the field is scrolled to theend.diff --git a/packages/core/src/TextArea/TextArea.test.tsx b/packages/core/src/TextArea/TextArea.test.tsxindex 59224419cf..eee5da18ac 100644--- a/packages/core/src/TextArea/TextArea.test.tsx+++ b/packages/core/src/TextArea/TextArea.test.tsx@@ -17,6 +17,7 @@ import * as stylex from '@stylexjs/stylex';import {colorVars} from '../theme/tokens.stylex';import {TestIcon} from '../__tests__/TestIcon';import {TextArea} from './TextArea';+import {InternationalizationProvider} from '../i18n';import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';// jsdom cannot match `:focus-visible`: compare the ring's StyleX class hash.@@ -521,6 +522,38 @@ describe('TextArea', () => {expect(screen.getByText('5/20')).toBeInTheDocument();});+ it('formats the counter from the catalog with locale number formatting', () => {+ render(+ <InternationalizationProvider+ locale="de-DE"+ overrides={{+ 'de-DE': {+ '@astryx.textArea.counter': '{count, number} von {limit, number}',+ },+ }}>+ <TextArea+ label="Bio"+ value={'a'.repeat(62)}+ onChange={() => {}}+ maxLength={2000}+ />+ </InternationalizationProvider>,+ );+ expect(screen.getByText('62 von 2.000')).toBeInTheDocument();+ });++ it('formats an English counter with grouped digits', () => {+ render(+ <TextArea+ label="Bio"+ value="hi"+ onChange={() => {}}+ maxLength={2000}+ />,+ );+ expect(screen.getByText('2/2,000')).toBeInTheDocument();+ });+it('does not display counter when maxLength is not provided', () => {render(<TextArea label="Description" value="Hello" onChange={() => {}} />,diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsxindex 32f474b269..a9dd004c46 100644--- a/packages/core/src/TextArea/TextArea.tsx+++ b/packages/core/src/TextArea/TextArea.tsx@@ -696,7 +696,10 @@ export function TextArea({// live-region announcement carry the meaning.<Icon icon="warning" size="sm" />)}- {valueLength}/{maxLength}+ {t('@astryx.textArea.counter', {+ count: valueLength,+ limit: maxLength,+ })}</div>)}</div>