An open source design system that's fully customizable and agent ready
TypeScript
fix(FileInput): a caller's aria props reach the trigger, not only the hidden input (#9031)
Ojas Mutrejaac6ac2250aea
diff --git a/.changeset/fileinput-caller-aria-on-trigger.md b/.changeset/fileinput-caller-aria-on-trigger.mdnew file mode 100644index 0000000000..5bb8b5269d--- /dev/null+++ b/.changeset/fileinput-caller-aria-on-trigger.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] FileInput: a caller's `aria-describedby` and other `aria-*` props now reach the trigger button, the field's focusable control. Before they were set only on the hidden native input, which is `aria-hidden` and never focused, so `aria-describedby="hint"` was never read ("Report" announced without "PDF only, up to 10 MB"). The caller's ids are now joined to the trigger's own description ids, first. The props the trigger composes itself (`aria-label`, `aria-labelledby`, `aria-invalid`, `aria-busy`, `aria-disabled`, `aria-hidden`) are not copied. See `family:input-fields` FR10.1. No API changes.++@HelloOjasMutrejadiff --git a/packages/core/src/FileInput/FileInput.test.tsx b/packages/core/src/FileInput/FileInput.test.tsxindex 54a27ff782..01b14410f5 100644--- a/packages/core/src/FileInput/FileInput.test.tsx+++ b/packages/core/src/FileInput/FileInput.test.tsx@@ -257,6 +257,48 @@ describe('FileInput', () => {expect(input).toHaveAttribute('aria-hidden', 'true');});+ it("joins a caller's aria-describedby to the trigger's own description", () => {+ render(+ <>+ <p id="hint">Up to 10 MB</p>+ <FileInput+ label="Report"+ description="PDF only"+ aria-describedby="hint"+ value={null}+ onChange={() => {}}+ />+ </>,+ );+ const trigger = screen.getByRole('button', {name: 'Report'});+ expect(trigger).toHaveAccessibleDescription('Up to 10 MB PDF only');+ });++ it("puts a caller's other aria-* props on the trigger, and keeps the ones it manages", () => {+ render(+ <FileInput+ label="Report"+ aria-details="details"+ aria-expanded={false}+ aria-posinset={1}+ aria-label="Ignored"+ value={null}+ onChange={() => {}}+ />,+ );+ const trigger = screen.getByRole('button', {name: 'Report'});+ expect(trigger).toHaveAttribute('aria-details', 'details');+ // Booleans and numbers reach the trigger too.+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ expect(trigger).toHaveAttribute('aria-posinset', '1');+ expect(trigger).toHaveAttribute('aria-label', 'Report');+ // The hidden input is still aria-hidden, whatever props it takes.+ expect(document.querySelector('input[type="file"]')).toHaveAttribute(+ 'aria-hidden',+ 'true',+ );+ });+it('does not mention required without isRequired', () => {render(<FileInput label="Resume" value={null} onChange={() => {}} />);const trigger = screen.getByRole('button', {name: 'Resume'});diff --git a/packages/core/src/FileInput/FileInput.tsx b/packages/core/src/FileInput/FileInput.tsxindex 0ece83b998..3083cdd615 100644--- a/packages/core/src/FileInput/FileInput.tsx+++ b/packages/core/src/FileInput/FileInput.tsx@@ -575,6 +575,33 @@ export function FileInput({.filter(Boolean).join(' ') || undefined;+ // The native input keeps taking the caller's base props (the shared FR10+ // contract), but it is `aria-hidden` and never focused, so a caller's+ // `aria-*` props are also set on the trigger, the field's focusable control,+ // where assistive tech reads them. The ones the trigger composes itself are+ // not copied, and a caller's description is joined to its own, first.+ const {+ 'aria-describedby': callerDescribedBy,+ 'aria-label': _callerLabel,+ 'aria-labelledby': _callerLabelledBy,+ 'aria-hidden': _callerHidden,+ 'aria-disabled': _callerDisabled,+ 'aria-busy': _callerBusy,+ 'aria-invalid': _callerInvalid,+ ...otherRest+ } = rest as typeof rest & Record<string, unknown>;+ const triggerAriaProps: Record<string, unknown> = {};+ for (const [key, value] of Object.entries(otherRest)) {+ // Booleans and numbers are valid ARIA values too: React serializes them.+ if (key.startsWith('aria-') && value != null) {+ triggerAriaProps[key] = value;+ }+ }+ const triggerDescribedBy =+ [callerDescribedBy, ariaDescribedBy]+ .filter(Boolean)+ .join(' ') || undefined;+const defaultPlaceholder = isMultiple? t('@astryx.fileInput.placeholderMultiple'): t('@astryx.fileInput.placeholder');@@ -946,8 +973,9 @@ export function FileInput({: label}aria-busy={isBusy || undefined}- aria-describedby={ariaDescribedBy}aria-invalid={status?.type === 'error' ? 'true' : undefined}+ {...triggerAriaProps}+ aria-describedby={triggerDescribedBy}/></VisuallyHidden><input