Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(NumberInput): localize the invalid-number announcement (#7482)

Harjoth Khara9b3e25a46ac6
diff --git a/.changeset/number-input-invalid-number-i18n.md b/.changeset/number-input-invalid-number-i18n.md
new file mode 100644
index 0000000000..928b1b7c41
--- /dev/null
+++ b/.changeset/number-input-invalid-number-i18n.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `NumberInput`: the screen-reader "Invalid number" alert now goes through the i18n translator, so an `InternationalizationProvider` locale or override can replace it. Adds `@astryx.numberInput.invalidNumber` to the `en` catalog. Locales without a translation yet still fall back to English.
+
+@harjothkhara
diff --git a/packages/core/locales/en.json b/packages/core/locales/en.json
index b4b127e594..0c2dc57de1 100644
--- a/packages/core/locales/en.json
+++ b/packages/core/locales/en.json
@@ -1287,6 +1287,10 @@
"defaultMessage": "Increment {label}",
"description": "Accessible label for the NumberInput button that increases the value by one configured step. Example: `Increment Quantity`."
},
+ "@astryx.numberInput.invalidNumber": {
+ "defaultMessage": "Invalid number",
+ "description": "Screen-reader-only live-region alert in NumberInput when the typed text is not a valid number for the field. The field silently reverts on blur, so this is the only rejection feedback a screen-reader user gets."
+ },
"@astryx.selector.clearLabel": {
"defaultMessage": "Clear {label}",
"description": "Screen-reader-only label on the X that clears the selected value from a Selector. `{label}` is the selector's visible label — example: `Clear Country`."
diff --git a/packages/core/src/NumberInput/NumberInput.test.tsx b/packages/core/src/NumberInput/NumberInput.test.tsx
index 78c1839f0e..48cd494556 100644
--- a/packages/core/src/NumberInput/NumberInput.test.tsx
+++ b/packages/core/src/NumberInput/NumberInput.test.tsx
@@ -1099,6 +1099,30 @@ describe('NumberInput', () => {
expect(screen.getByRole('alert')).toHaveTextContent('Invalid number');
});
+ it('resolves the invalid-number announcement from the i18n catalog', async () => {
+ const user = userEvent.setup();
+ render(
+ <InternationalizationProvider
+ locale="ar-SA"
+ overrides={{
+ 'ar-SA': {'@astryx.numberInput.invalidNumber': 'رقم غير صالح'},
+ }}>
+ <NumberInput
+ label="Count"
+ value={null}
+ onChange={() => {}}
+ isIntegerOnly
+ />
+ </InternationalizationProvider>,
+ );
+
+ const input = screen.getByRole('spinbutton');
+ await user.click(input);
+ await user.type(input, '3.5');
+
+ expect(screen.getByRole('alert')).toHaveTextContent('رقم غير صالح');
+ });
+
it('does not announce an alert message when input is valid', async () => {
const user = userEvent.setup();
render(<NumberInput label="Count" value={null} onChange={() => {}} />);
diff --git a/packages/core/src/NumberInput/NumberInput.tsx b/packages/core/src/NumberInput/NumberInput.tsx
index bbcc6ea307..af9cb5e135 100644
--- a/packages/core/src/NumberInput/NumberInput.tsx
+++ b/packages/core/src/NumberInput/NumberInput.tsx
@@ -977,7 +977,7 @@ export function NumberInput({
user would get no feedback that their entry was rejected (WCAG 3.3.1).
*/}
<VisuallyHidden as="div" role="alert" aria-live="assertive">
- {!isInputValid ? 'Invalid number' : ''}
+ {!isInputValid ? t('@astryx.numberInput.invalidNumber') : ''}
</VisuallyHidden>
{hasClear && value != null && !isDisabled && !isReadOnly && (
<InputClearButton