An open source design system that's fully customizable and agent ready
TypeScript
fix(input): exclude disabled TextInput/TextArea/NumberInput from form data (#4811)
Joeye6af10a379c0
diff --git a/.changeset/disabled-inputs-form-data.md b/.changeset/disabled-inputs-form-data.mdnew file mode 100644index 0000000000..781bddb53a--- /dev/null+++ b/.changeset/disabled-inputs-form-data.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] TextInput, TextArea, NumberInput: a disabled field is no longer submitted with the form when `disabledMessage` is set. Showing the reason tooltip requires swapping the native `disabled` attribute for `aria-disabled` + `readOnly`, so the message stays discoverable by pointer and keyboard — but read-only fields still serialize into `FormData`, and these three kept their `name`, so a locked field posted its value. They now withhold the `name` while disabled, matching CheckboxInput and Switch (which forward the name only when enabled) and the hidden-input carriers in Selector, MultiSelector, Slider, and Tokenizer (which mirror `disabled`). Adds form-participation coverage to all three so the guarantee is pinned.+@josephfarinadiff --git a/packages/core/src/NumberInput/NumberInput.test.tsx b/packages/core/src/NumberInput/NumberInput.test.tsxindex af80473df6..e16e39a9f0 100644--- a/packages/core/src/NumberInput/NumberInput.test.tsx+++ b/packages/core/src/NumberInput/NumberInput.test.tsx@@ -687,6 +687,61 @@ describe('NumberInput', () => {});});+ describe('form participation', () => {+ it('submits the value under htmlName', () => {+ const {container} = render(+ <form>+ <NumberInput+ label="Quantity"+ htmlName="quantity"+ value={42}+ onChange={() => {}}+ />+ </form>,+ );+ const data = new FormData(container.querySelector('form')!);+ expect(data.get('quantity')).toBe('42');+ });++ it('is excluded from form data when disabled', () => {+ const {container} = render(+ <form>+ <NumberInput+ label="Quantity"+ htmlName="quantity"+ value={42}+ onChange={() => {}}+ isDisabled+ />+ </form>,+ );+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);+ });++ // Regression: a disabledMessage swaps the native `disabled` attribute for+ // aria-disabled + readOnly so the reason stays focus-discoverable, but+ // read-only fields still submit — the name has to be withheld too.+ it('is excluded from form data when disabled, even with a disabledMessage', () => {+ const {container} = render(+ <form>+ <NumberInput+ label="Quantity"+ htmlName="quantity"+ value={42}+ onChange={() => {}}+ isDisabled+ disabledMessage="Quantity is fixed by the contract"+ />+ </form>,+ );+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);+ });+ });+describe('autoComplete prop', () => {it('sets autocomplete attribute when autoComplete is provided', () => {render(diff --git a/packages/core/src/NumberInput/NumberInput.tsx b/packages/core/src/NumberInput/NumberInput.tsxindex 0a53eb0511..69dbf1b579 100644--- a/packages/core/src/NumberInput/NumberInput.tsx+++ b/packages/core/src/NumberInput/NumberInput.tsx@@ -655,7 +655,7 @@ export function NumberInput({{...rest}ref={mergeRefs(ref, inputRef)}id={id}- name={htmlName}+ name={isDisabled ? undefined : htmlName}type="number"autoComplete={autoComplete}value={displayValue}diff --git a/packages/core/src/TextArea/TextArea.test.tsx b/packages/core/src/TextArea/TextArea.test.tsxindex e65e3f7d44..16eba3cea3 100644--- a/packages/core/src/TextArea/TextArea.test.tsx+++ b/packages/core/src/TextArea/TextArea.test.tsx@@ -673,6 +673,61 @@ describe('TextArea', () => {});});+ describe('form participation', () => {+ it('submits the value under htmlName', () => {+ const {container} = render(+ <form>+ <TextArea+ label="Notes"+ htmlName="notes"+ value="hello"+ onChange={() => {}}+ />+ </form>,+ );+ const data = new FormData(container.querySelector('form')!);+ expect(data.get('notes')).toBe('hello');+ });++ it('is excluded from form data when disabled', () => {+ const {container} = render(+ <form>+ <TextArea+ label="Notes"+ htmlName="notes"+ value="hello"+ onChange={() => {}}+ isDisabled+ />+ </form>,+ );+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);+ });++ // Regression: a disabledMessage swaps the native `disabled` attribute for+ // aria-disabled + readOnly so the reason stays focus-discoverable, but+ // read-only fields still submit — the name has to be withheld too.+ it('is excluded from form data when disabled, even with a disabledMessage', () => {+ const {container} = render(+ <form>+ <TextArea+ label="Notes"+ htmlName="notes"+ value="hello"+ onChange={() => {}}+ isDisabled+ disabledMessage="Notes are locked while the review is open"+ />+ </form>,+ );+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);+ });+ });+describe('click-to-focus', () => {it('focuses textarea when clicking the start icon', () => {render(diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsxindex 51fe4d25ca..4aadedc5d5 100644--- a/packages/core/src/TextArea/TextArea.tsx+++ b/packages/core/src/TextArea/TextArea.tsx@@ -544,7 +544,7 @@ export function TextArea({{...rest}ref={mergeRefs(ref, textareaRef)}id={id}- name={htmlName}+ name={isDisabled ? undefined : htmlName}value={optimisticValue}onChange={handleChange}onPaste={onPaste}diff --git a/packages/core/src/TextInput/TextInput.test.tsx b/packages/core/src/TextInput/TextInput.test.tsxindex e6f014ba60..22f36e362b 100644--- a/packages/core/src/TextInput/TextInput.test.tsx+++ b/packages/core/src/TextInput/TextInput.test.tsx@@ -371,6 +371,61 @@ describe('TextInput', () => {});});+ describe('form participation', () => {+ it('submits the value under htmlName', () => {+ const {container} = render(+ <form>+ <TextInput+ label="Owner"+ htmlName="owner"+ value="alice"+ onChange={() => {}}+ />+ </form>,+ );+ const data = new FormData(container.querySelector('form')!);+ expect(data.get('owner')).toBe('alice');+ });++ it('is excluded from form data when disabled', () => {+ const {container} = render(+ <form>+ <TextInput+ label="Owner"+ htmlName="owner"+ value="alice"+ onChange={() => {}}+ isDisabled+ />+ </form>,+ );+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);+ });++ // Regression: a disabledMessage swaps the native `disabled` attribute for+ // aria-disabled + readOnly so the reason stays focus-discoverable, but+ // read-only fields still submit — the name has to be withheld too.+ it('is excluded from form data when disabled, even with a disabledMessage', () => {+ const {container} = render(+ <form>+ <TextInput+ label="Owner"+ htmlName="owner"+ value="alice"+ onChange={() => {}}+ isDisabled+ disabledMessage="You need the Editor role to change this"+ />+ </form>,+ );+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);+ });+ });+describe('onEnter', () => {it('calls onEnter when Enter key is pressed', async () => {const user = userEvent.setup();diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsxindex e9df6a5dd7..4767637ea5 100644--- a/packages/core/src/TextInput/TextInput.tsx+++ b/packages/core/src/TextInput/TextInput.tsx@@ -428,7 +428,7 @@ export function TextInput({{...rest}ref={mergeRefs(ref, inputRef)}id={id}- name={htmlName}+ name={isDisabled ? undefined : htmlName}type={type}value={optimisticValue}onChange={handleChange}