An open source design system that's fully customizable and agent ready
TypeScript
fix(ListInput): route all visible and AT-facing strings through i18n (#4967)
Ojas Mutreja1e823c15344d
diff --git a/.changeset/listinput-i18n-catalog.md b/.changeset/listinput-i18n-catalog.mdnew file mode 100644index 0000000000..318e5a624b--- /dev/null+++ b/.changeset/listinput-i18n-catalog.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Added a `@astryx.listInput.*` catalog namespace to `packages/core/locales/en.json` so the lab `ListInput` component's action labels, empty state, reorder instructions, and live announcements can be translated. `ListInput` previously hardcoded every visible and assistive-technology-facing string.++@HelloOjasMutrejadiff --git a/packages/core/locales/en.json b/packages/core/locales/en.jsonindex 1d39ff2238..e6a8a45487 100644--- a/packages/core/locales/en.json+++ b/packages/core/locales/en.json@@ -419,6 +419,66 @@"defaultMessage": "Next","description": "Screen-reader-only label on the right-arrow button in a Lightbox (navigates to next media item). Pairs with `lightbox.previous`."},+ "@astryx.listInput.emptyTitle": {+ "defaultMessage": "No {itemName}s yet",+ "description": "EmptyState title shown inside a lab ListInput when its collection has no records. `{itemName}` is the consumer's singular noun for one record (e.g. \"guest\"); the source appends a literal \"s\" to pluralize it, which only works for regular English plurals. If your language cannot pluralize an interpolated noun this way, rephrase around `{itemName}` instead (e.g. \"No {itemName} added yet\")."+ },+ "@astryx.listInput.emptyDescription": {+ "defaultMessage": "Add a {itemName} to get started.",+ "description": "EmptyState supporting text shown inside a lab ListInput when its collection has no records. `{itemName}` is the consumer's singular noun for one record (e.g. \"guest\")."+ },+ "@astryx.listInput.addItem": {+ "defaultMessage": "Add {itemName}",+ "description": "Accessible label on the button that appends a new record to a lab ListInput. `{itemName}` is the consumer's singular noun for one record (e.g. \"guest\")."+ },+ "@astryx.listInput.removeItem": {+ "defaultMessage": "Remove {itemName} {position, number}",+ "description": "Accessible label and tooltip on the button that deletes one record from a lab ListInput. `{itemName}` is the consumer's singular noun for one record; `{position}` is its 1-based row number (e.g. \"Remove guest 2\")."+ },+ "@astryx.listInput.reorderItem": {+ "defaultMessage": "Reorder {itemName} {position, number}",+ "description": "Accessible label on the drag-handle button that reorders one record in a lab ListInput. `{itemName}` is the consumer's singular noun for one record; `{position}` is its 1-based row number (e.g. \"Reorder guest 2\")."+ },+ "@astryx.listInput.fieldLabelWithPosition": {+ "defaultMessage": "{header}, {itemName} {position, number} of {total, number}",+ "description": "Accessible name for a field inside a lab ListInput row after the first row, disambiguating repeated column labels. `{header}` is the column's own label (e.g. \"Name\"); `{itemName}` is the consumer's singular noun for one record; `{position}`/`{total}` are the row's 1-based index and the total row count (e.g. \"Name, guest 2 of 3\")."+ },+ "@astryx.listInput.reorderInstructions": {+ "defaultMessage": "Use Arrow Up or Arrow Down to move this item one position. Press Space or Enter to pick it up for extended keyboard reordering.",+ "description": "Visually-hidden instructions describing how to use a lab ListInput row's keyboard reorder handle, referenced via aria-describedby from every reorder button."+ },+ "@astryx.listInput.announceAdded": {+ "defaultMessage": "Added {itemName} {position, number}.",+ "description": "Screen-reader-only live announcement after a new record is appended to a lab ListInput. `{itemName}` is the consumer's singular noun for one record; `{position}` is the new record's 1-based row number."+ },+ "@astryx.listInput.announceRemoved": {+ "defaultMessage": "Removed {itemName} {position, number}.",+ "description": "Screen-reader-only live announcement after a record is deleted from a lab ListInput. `{itemName}` is the consumer's singular noun for one record; `{position}` is the removed record's former 1-based row number."+ },+ "@astryx.listInput.announceGrabbed": {+ "defaultMessage": "{itemName} {position, number} grabbed. Use arrow keys to move, Space or Enter to drop, and Escape to cancel.",+ "description": "Screen-reader-only live announcement when a lab ListInput record's keyboard reorder handle enters extended \"lift\" mode. `{itemName}` is the consumer's singular noun for one record; `{position}` is its 1-based row number."+ },+ "@astryx.listInput.announceMovedToPosition": {+ "defaultMessage": "{itemName} moved to position {position, number} of {total, number}.",+ "description": "Screen-reader-only live announcement each time a lab ListInput record's reorder position changes (arrow-key step, keyboard lift-mode preview, or pointer drag). `{itemName}` is the consumer's singular noun for one record; `{position}`/`{total}` are the record's new 1-based position and the total row count."+ },+ "@astryx.listInput.announceReorderCancelled": {+ "defaultMessage": "Reordering cancelled.",+ "description": "Screen-reader-only live announcement when a lab ListInput reorder in progress is cancelled (Escape key, blur, or the collection becoming disabled/loading mid-drag)."+ },+ "@astryx.listInput.announceReturnedToPosition": {+ "defaultMessage": "{itemName} returned to position {position, number}.",+ "description": "Screen-reader-only live announcement when a lab ListInput reorder is committed without the record's position actually changing. `{itemName}` is the consumer's singular noun for one record; `{position}` is its unchanged 1-based row number."+ },+ "@astryx.listInput.announceDropped": {+ "defaultMessage": "{itemName} dropped at position {position, number} of {total, number}.",+ "description": "Screen-reader-only live announcement when a lab ListInput reorder is committed with the record's position actually changing. `{itemName}` is the consumer's singular noun for one record; `{position}`/`{total}` are its new 1-based position and the total row count."+ },+ "@astryx.listInput.announceAlreadyAtBoundary": {+ "defaultMessage": "This {itemName} is already {boundary, select, first {first} last {last} other {}}.",+ "description": "Screen-reader-only live announcement when an arrow-key reorder attempt has no effect because the record is already at that end of the list. `{itemName}` is the consumer's singular noun for one record; `{boundary}` is always exactly \"first\" or \"last\"."+ },"@astryx.markdown.taskList": {"defaultMessage": "Task list","description": "Screen-reader-only accessible name for a GitHub-flavored Markdown task list (rendered from `- [ ] item` / `- [x] done` syntax)."diff --git a/packages/lab/src/ListInput/ListInput.test.tsx b/packages/lab/src/ListInput/ListInput.test.tsxindex 791cbbb181..b0f2e0ae2a 100644--- a/packages/lab/src/ListInput/ListInput.test.tsx+++ b/packages/lab/src/ListInput/ListInput.test.tsx@@ -11,7 +11,13 @@import {afterEach, describe, expect, it, vi} from 'vitest';import {useState} from 'react';-import {fireEvent, render, screen, within} from '@testing-library/react';+import {+ fireEvent,+ render,+ screen,+ waitFor,+ within,+} from '@testing-library/react';import {TextInput} from '@astryxdesign/core/TextInput';import {ListInput,@@ -484,7 +490,7 @@ describe('ListInput', () => {});});- it('animates live add and removal reflow after the controlled change', () => {+ it('animates live add and removal reflow after the controlled change', async () => {const events: string[] = [];const animate = mockMutationAnimations(events);@@ -525,11 +531,13 @@ describe('ListInput', () => {easing: 'cubic-bezier(0.24, 1, 0.4, 1)',},]);- expect(- Array.from(document.querySelectorAll('[aria-live="polite"]')).some(- node => node.textContent === 'Added guest 3.',- ),- ).toBe(true);+ await waitFor(() => {+ expect(+ Array.from(document.querySelectorAll('[aria-live="polite"]')).some(+ node => node.textContent === 'Added guest 3.',+ ),+ ).toBe(true);+ });const removeEventStart = events.length;const animationCountBeforeRemove = animate.mock.calls.length;@@ -554,14 +562,16 @@ describe('ListInput', () => {);}),).toBe(true);- expect(- Array.from(document.querySelectorAll('[aria-live="polite"]')).some(- node => node.textContent === 'Removed guest 1.',- ),- ).toBe(true);+ await waitFor(() => {+ expect(+ Array.from(document.querySelectorAll('[aria-live="polite"]')).some(+ node => node.textContent === 'Removed guest 1.',+ ),+ ).toBe(true);+ });});- it('uses instant add and remove changes when reduced motion is requested', () => {+ it('uses instant add and remove changes when reduced motion is requested', async () => {const animate = mockMutationAnimations();vi.spyOn(window, 'matchMedia').mockImplementation(query =>@@ -598,11 +608,13 @@ describe('ListInput', () => {expect(animate).not.toHaveBeenCalled();expect(screen.queryByDisplayValue('Ada')).not.toBeInTheDocument();expect(screen.getByRole('button', {name: 'Add guest'})).toHaveFocus();- expect(- Array.from(document.querySelectorAll('[aria-live="polite"]')).some(- node => node.textContent === 'Removed guest 1.',- ),- ).toBe(true);+ await waitFor(() => {+ expect(+ Array.from(document.querySelectorAll('[aria-live="polite"]')).some(+ node => node.textContent === 'Removed guest 1.',+ ),+ ).toBe(true);+ });fireEvent.click(screen.getByRole('button', {name: 'Add guest'}));expect(animate).not.toHaveBeenCalled();@@ -1033,7 +1045,7 @@ describe('ListInput', () => {).not.toBeInTheDocument();});- it('activates a pointer drag after horizontal threshold movement', () => {+ it('activates a pointer drag after horizontal threshold movement', async () => {const onChange = vi.fn();renderListInput({isReorderable: true, onChange});const rows = document.querySelectorAll<HTMLElement>(@@ -1071,9 +1083,13 @@ describe('ListInput', () => {fireEvent.pointerUp(handle, {pointerId: 9, clientX: 15, clientY: 10});expect(onChange).not.toHaveBeenCalled();- expect(- screen.getByText('guest returned to position 1.'),- ).toBeInTheDocument();+ await waitFor(() => {+ expect(+ Array.from(document.querySelectorAll('[aria-live="polite"]')).some(+ node => node.textContent === 'guest returned to position 1.',+ ),+ ).toBe(true);+ });});it('cancels a keyboard reorder with Escape', () => {diff --git a/packages/lab/src/ListInput/ListInput.tsx b/packages/lab/src/ListInput/ListInput.tsxindex 918ae5054d..2622ba0a21 100644--- a/packages/lab/src/ListInput/ListInput.tsx+++ b/packages/lab/src/ListInput/ListInput.tsx@@ -34,8 +34,9 @@ import {EmptyState} from '@astryxdesign/core/EmptyState';import {Field, type InputStatus} from '@astryxdesign/core/Field';import {FieldStatus} from '@astryxdesign/core/FieldStatus';import {Icon} from '@astryxdesign/core/Icon';-import {useMediaQuery} from '@astryxdesign/core/hooks';+import {useAnnounce, useMediaQuery} from '@astryxdesign/core/hooks';import {IconButton} from '@astryxdesign/core/IconButton';+import {useTranslator} from '@astryxdesign/core/i18n';import {useLayer} from '@astryxdesign/core/Layer';import {SizeProvider} from '@astryxdesign/core/SizeContext';import type {ColumnWidth} from '@astryxdesign/core/Table';@@ -662,7 +663,8 @@ export function ListInput<T>({const [reorderState, setReorderStateState] = useState<ReorderState<T> | null>(null,);- const [announcement, setAnnouncement] = useState('');+ const t = useTranslator();+ const announce = useAnnounce();const {tokens: themeTokens} = useTheme();const mutationDuration = parseDuration(themeTokens['--duration-fast-max'] ?? '',@@ -762,9 +764,9 @@ export function ListInput<T>({useEffect(() => {if ((isDisabled || isLoading) && reorderStateRef.current) {setReorderState(null);- setAnnouncement('Reordering cancelled.');+ announce(t('@astryx.listInput.announceReorderCancelled'));}- }, [isDisabled, isLoading]);+ }, [isDisabled, isLoading, announce, t]);useEffect(() => {const activeAnimations = activeMutationAnimationsRef.current;@@ -1114,7 +1116,12 @@ export function ListInput<T>({addPointerAnchorTopRef.current = null;prepareMutationMotion(nextValue);onChange(nextValue, {type: 'add', item, index: value.length});- setAnnouncement(`Added ${itemName} ${value.length + 1}.`);+ announce(+ t('@astryx.listInput.announceAdded', {+ itemName,+ position: value.length + 1,+ }),+ );};const handleUpdate = (@@ -1158,7 +1165,9 @@ export function ListInput<T>({: {itemKey: String(getItemKey(nextFocusItem)), target: 'remove'};prepareMutationMotion(nextValue);onChange(nextValue, {type: 'remove', item: removedItem, index});- setAnnouncement(`Removed ${itemName} ${index + 1}.`);+ announce(+ t('@astryx.listInput.announceRemoved', {itemName, position: index + 1}),+ );};const startReorder = (@@ -1191,8 +1200,8 @@ export function ListInput<T>({...pointerGeometry,hasPointerMoved: false,});- setAnnouncement(- `${itemName} ${index + 1} grabbed. Use arrow keys to move, Space or Enter to drop, and Escape to cancel.`,+ announce(+ t('@astryx.listInput.announceGrabbed', {itemName, position: index + 1}),);};@@ -1209,8 +1218,12 @@ export function ListInput<T>({return;}setReorderState({...currentState, toIndex: boundedIndex});- setAnnouncement(- `${itemName} moved to position ${boundedIndex + 1} of ${currentState.originalValue.length}.`,+ announce(+ t('@astryx.listInput.announceMovedToPosition', {+ itemName,+ position: boundedIndex + 1,+ total: currentState.originalValue.length,+ }),);};@@ -1219,7 +1232,7 @@ export function ListInput<T>({return;}setReorderState(null);- setAnnouncement('Reordering cancelled.');+ announce(t('@astryx.listInput.announceReorderCancelled'));};const commitReorder = () => {@@ -1245,8 +1258,11 @@ export function ListInput<T>({setReorderState(null);}if (!hasChanged) {- setAnnouncement(- `${itemName} returned to position ${currentState.fromIndex + 1}.`,+ announce(+ t('@astryx.listInput.announceReturnedToPosition', {+ itemName,+ position: currentState.fromIndex + 1,+ }),);return;}@@ -1262,16 +1278,23 @@ export function ListInput<T>({} else {commit();}- setAnnouncement(- `${itemName} dropped at position ${currentState.toIndex + 1} of ${currentState.originalValue.length}.`,+ announce(+ t('@astryx.listInput.announceDropped', {+ itemName,+ position: currentState.toIndex + 1,+ total: currentState.originalValue.length,+ }),);};const moveWithArrowKey = (item: T, fromIndex: number, offset: -1 | 1) => {cancelMutationAnimations();const toIndex = Math.max(0, Math.min(fromIndex + offset, value.length - 1));if (toIndex === fromIndex) {- setAnnouncement(- `This ${itemName} is already ${offset < 0 ? 'first' : 'last'}.`,+ announce(+ t('@astryx.listInput.announceAlreadyAtBoundary', {+ itemName,+ boundary: offset < 0 ? 'first' : 'last',+ }),);return;}@@ -1284,8 +1307,12 @@ export function ListInput<T>({toIndex,}),);- setAnnouncement(- `${itemName} moved to position ${toIndex + 1} of ${value.length}.`,+ announce(+ t('@astryx.listInput.announceMovedToPosition', {+ itemName,+ position: toIndex + 1,+ total: value.length,+ }),);};@@ -1394,8 +1421,12 @@ export function ListInput<T>({}setReorderState(nextState);if (hasCrossedThreshold && activeState.toIndex !== targetIndex) {- setAnnouncement(- `${itemName} moved to position ${targetIndex + 1} of ${activeState.originalValue.length}.`,+ announce(+ t('@astryx.listInput.announceMovedToPosition', {+ itemName,+ position: targetIndex + 1,+ total: activeState.originalValue.length,+ }),);}};@@ -1473,8 +1504,10 @@ export function ListInput<T>({data-list-input-motion-key="state:empty"{...stylex.props(styles.emptyItem)}><EmptyState- title={`No ${itemName}s yet`}- description={`Add a ${itemName} to get started.`}+ title={t('@astryx.listInput.emptyTitle', {itemName})}+ description={t('@astryx.listInput.emptyDescription', {+ itemName,+ })}isCompact/></li>@@ -1542,7 +1575,12 @@ export function ListInput<T>({);const isRepeatedLabel = index !== 0;const cellLabel = isRepeatedLabel- ? `${column.header}, ${itemName} ${index + 1} of ${displayValue.length}`+ ? t('@astryx.listInput.fieldLabelWithPosition', {+ header: column.header,+ itemName,+ position: index + 1,+ total: displayValue.length,+ }): column.header;const valueContext: ListInputValueContext<T> = {item,@@ -1597,8 +1635,14 @@ export function ListInput<T>({styles.removeControlCell,)}><IconButton- label={`Remove ${itemName} ${index + 1}`}- tooltip={`Remove ${itemName} ${index + 1}`}+ label={t('@astryx.listInput.removeItem', {+ itemName,+ position: index + 1,+ })}+ tooltip={t('@astryx.listInput.removeItem', {+ itemName,+ position: index + 1,+ })}icon={<Icon icon="close" size="sm" />}variant="ghost"size="md"@@ -1615,7 +1659,10 @@ export function ListInput<T>({styles.reorderControlCell,)}><IconButton- label={`Reorder ${itemName} ${index + 1}`}+ label={t('@astryx.listInput.reorderItem', {+ itemName,+ position: index + 1,+ })}icon={<Icon icon={GripVerticalIcon} size="sm" />}variant="ghost"size="md"@@ -1746,7 +1793,7 @@ export function ListInput<T>({{...stylex.props(styles.actionContent, contentGridStyle)}><Buttonref={addButtonRef}- label={`Add ${itemName}`}+ label={t('@astryx.listInput.addItem', {itemName})}variant="secondary"size="md"width="100%"@@ -1762,13 +1809,9 @@ export function ListInput<T>({</div>{showReorderColumn ? (<VisuallyHidden as="div" id={reorderInstructionsID}>- Use Arrow Up or Arrow Down to move this item one position. Press- Space or Enter to pick it up for extended keyboard reordering.+ {t('@astryx.listInput.reorderInstructions')}</VisuallyHidden>) : null}- <VisuallyHidden as="div" aria-live="polite" aria-atomic="true">- {announcement}- </VisuallyHidden></div></Field>{dragPreviewPosition != null