An open source design system that's fully customizable and agent ready
TypeScript
fix(Spinner): localize the default assistive label through the i18n catalog (#6217)
홍규진5ca036254694
diff --git a/.changeset/spinner-default-label-i18n.md b/.changeset/spinner-default-label-i18n.mdnew file mode 100644index 0000000000..a097cfed38--- /dev/null+++ b/.changeset/spinner-default-label-i18n.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Spinner: the default assistive label now comes from the translation catalog (`@astryx.spinner.loading`) instead of a literal `"Loading"` in component source, so a localized app translates the status. An explicit `aria-label` and a visible string label still take precedence, in that order.++@Kyujeniusdiff --git a/packages/core/locales/en.json b/packages/core/locales/en.jsonindex 5ef1e6ac81..418f4d45e2 100644--- a/packages/core/locales/en.json+++ b/packages/core/locales/en.json@@ -935,6 +935,10 @@"defaultMessage": "Loading","description": "Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense (\"work in progress\"), not a noun. Kept separate from `typeahead.loading` — translations may diverge."},+ "@astryx.spinner.loading": {+ "defaultMessage": "Loading",+ "description": "Screen-reader-only default name for a standalone Spinner's role=\"status\" element, used when the consumer supplies neither `aria-label` nor a visible string label. Present-progressive form. Kept separate from `button.loading` and `typeahead.loading` — translations may diverge."+ },"@astryx.chatComposerDrawer.expand": {"defaultMessage": "Expand {label}","description": "Screen-reader-only label on the ChatComposerDrawer toggle when the drawer is collapsed. `{label}` is the drawer's visible name — example: `Expand Attachments`. Pairs with `collapse`."diff --git a/packages/core/src/Spinner/Spinner.doc.mjs b/packages/core/src/Spinner/Spinner.doc.mjsindex 31fea1e704..788054af05 100644--- a/packages/core/src/Spinner/Spinner.doc.mjs+++ b/packages/core/src/Spinner/Spinner.doc.mjs@@ -30,7 +30,7 @@ export const docs = {name: 'aria-label',type: 'string',description:- 'Accessible name for screen readers. Defaults to label (if string) or "Loading".',+ 'Accessible name for screen readers. Defaults to label (if string) or a translated "Loading" from the i18n catalog.',default: "'Loading'",},{@@ -88,7 +88,7 @@ export const docsZh = {{name: 'aria-label',type: 'string',- description: '屏幕阅读器的无障碍名称。默认为 label(如果是字符串)或 "Loading"。',+ description: '屏幕阅读器的无障碍名称。默认为 label(如果是字符串)或来自 i18n 词条的已翻译 "Loading"。',default: "'Loading'",},{@@ -138,7 +138,8 @@ export const docsDense = {size: 'Spinner size: ring diameter (10px, 14px, 18px, 28px).',shade: 'Color shade for light or dark backgrounds.',label: 'Visible content below spinner. String auto-sets aria-label.',- 'aria-label': 'A11y name for screen readers. Defaults to label or "Loading".',+ 'aria-label':+ 'A11y name for screen readers. Defaults to label or a translated "Loading".',xstyle: 'StyleX styles for layout customization. Must be stylex.create() value, not inline style.',},};\ No newline at end of filediff --git a/packages/core/src/Spinner/Spinner.test.tsx b/packages/core/src/Spinner/Spinner.test.tsxindex 5dfdfca5b2..0168a621bc 100644--- a/packages/core/src/Spinner/Spinner.test.tsx+++ b/packages/core/src/Spinner/Spinner.test.tsx@@ -12,6 +12,7 @@import {describe, it, expect, vi, afterEach} from 'vitest';import {render, screen} from '@testing-library/react';import {Spinner} from './Spinner';+import {InternationalizationProvider} from '../i18n';import {defineTheme} from '../theme/defineTheme';import {generateThemeCSS} from '../theme/generateThemeRules';@@ -72,6 +73,34 @@ describe('Spinner', () => {expect(spinner).toHaveAttribute('data-shade', 'inherit');});+ it('localizes the default assistive label through the i18n catalog', () => {+ render(+ <InternationalizationProvider+ locale="fr"+ overrides={{fr: {'@astryx.spinner.loading': 'Chargement'}}}>+ <Spinner data-testid="spinner" />+ </InternationalizationProvider>,+ );+ expect(screen.getByTestId('spinner')).toHaveAttribute(+ 'aria-label',+ 'Chargement',+ );+ });++ it('keeps an explicit aria-label over the localized default', () => {+ render(+ <InternationalizationProvider+ locale="fr"+ overrides={{fr: {'@astryx.spinner.loading': 'Chargement'}}}>+ <Spinner aria-label="Veuillez patienter" data-testid="spinner" />+ </InternationalizationProvider>,+ );+ expect(screen.getByTestId('spinner')).toHaveAttribute(+ 'aria-label',+ 'Veuillez patienter',+ );+ });+it('does not duplicate a visible string label as aria-label', () => {render(<Spinner label="Fetching data" data-testid="spinner" />);const status = screen.getByRole('status');diff --git a/packages/core/src/Spinner/Spinner.tsx b/packages/core/src/Spinner/Spinner.tsxindex ecd56f144f..e6a5837ef5 100644--- a/packages/core/src/Spinner/Spinner.tsx+++ b/packages/core/src/Spinner/Spinner.tsx@@ -4,7 +4,7 @@/*** @file Spinner.tsx- * @input Uses React, StyleX, SVG rendering+ * @input Uses React, i18n (useTranslator), StyleX, SVG rendering* @output Exports Spinner component, SpinnerProps, SpinnerSize, SpinnerShade types* @position Core implementation of spinner loading indicator*@@ -22,6 +22,7 @@ import {colorVars, durationVars, spacingVars} from '../theme/tokens.stylex';import type {BaseProps} from '../BaseProps';import {Text} from '../Text/Text';import {mergeProps} from '../utils';+import {useTranslator} from '../i18n';import {themeProps} from '../utils/themeProps';// =============================================================================@@ -495,6 +496,7 @@ export function Spinner({const arcLength = circumference * ARC_FRACTION;const hasLabel = label != null;const labelId = useId();+ const t = useTranslator();// When a visible string label renders (and no explicit aria-label is set),// name the status element from the visible Text via aria-labelledby instead@@ -503,9 +505,13 @@ export function Spinner({const namedByVisibleLabel =hasLabel && typeof label === 'string' && ariaLabel == null;- // Resolve accessible name: explicit aria-label > string label > "Loading"+ // Resolve accessible name: explicit aria-label > string label > the+ // localized default. The fallback is AT-facing text, so it goes through the+ // translation runtime like visible text does.const resolvedAriaLabel =- ariaLabel ?? (typeof label === 'string' ? label : undefined) ?? 'Loading';+ ariaLabel ??+ (typeof label === 'string' ? label : undefined) ??+ t('@astryx.spinner.loading');const spinner = (<span