An open source design system that's fully customizable and agent ready
TypeScript
fix(input): required disabled CheckboxInput/Switch no longer block form submit (#4815)
Joeyfcd87731f0d2
diff --git a/.changeset/required-disabled-blocks-submit.md b/.changeset/required-disabled-blocks-submit.mdnew file mode 100644index 0000000000..afadb06691--- /dev/null+++ b/.changeset/required-disabled-blocks-submit.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] CheckboxInput, Switch: a `required` control that is disabled with a `disabledMessage` no longer blocks the whole form from submitting. Showing the reason tooltip swaps the native `disabled` attribute for `aria-disabled`, which leaves the control subject to constraint validation — so an unchecked required checkbox (or an off required switch) the user has been told they cannot touch made the form permanently unsubmittable, with the browser reporting a validation error against a control they had no way to satisfy. Both now detach from the form via `form=""` while focusable-disabled, matching a natively disabled control and the treatment RadioListItem already applied. Enabled controls are unaffected — a required, unchecked checkbox still blocks submission as it should.+@josephfarinadiff --git a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx b/packages/core/src/CheckboxInput/CheckboxInput.test.tsxindex 1b37a1c853..ddd879f47f 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.test.tsx@@ -544,6 +544,38 @@ describe('CheckboxInput', () => {expect(data.get('terms')).toBe('on');});+ it('does not block form submission when required and disabled with a disabledMessage', () => {+ const {container} = render(+ <form>+ <CheckboxInput+ label="Terms"+ htmlName="terms"+ value={false}+ onChange={() => {}}+ isRequired+ isDisabled+ disabledMessage="Terms are managed by your administrator"+ />+ </form>,+ );+ expect(container.querySelector('form')!.checkValidity()).toBe(true);+ });++ it('still blocks submission when required and unchecked but enabled', () => {+ const {container} = render(+ <form>+ <CheckboxInput+ label="Terms"+ htmlName="terms"+ value={false}+ onChange={() => {}}+ isRequired+ />+ </form>,+ );+ expect(container.querySelector('form')!.checkValidity()).toBe(false);+ });+it('is excluded from form data when disabled, even with a disabledMessage', () => {const {container} = render(<form>diff --git a/packages/core/src/CheckboxInput/CheckboxInput.tsx b/packages/core/src/CheckboxInput/CheckboxInput.tsxindex 13edf980d3..eab1c41935 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.tsx@@ -398,6 +398,7 @@ export function CheckboxInput({// still blocked by the isDisabled guard in onChange below.disabled={isDisabled && !isFocusableDisabled}aria-disabled={isFocusableDisabled ? 'true' : undefined}+ form={isFocusableDisabled ? '' : undefined}readOnly={isReadOnly}required={isRequired}onChange={e => {diff --git a/packages/core/src/Switch/Switch.test.tsx b/packages/core/src/Switch/Switch.test.tsxindex 0395424880..986f099102 100644--- a/packages/core/src/Switch/Switch.test.tsx+++ b/packages/core/src/Switch/Switch.test.tsx@@ -636,6 +636,38 @@ describe('Switch', () => {expect(data.get('notify')).toBe('on');});+ it('does not block form submission when required and disabled with a disabledMessage', () => {+ const {container} = render(+ <form>+ <Switch+ label="Notify"+ htmlName="notify"+ value={false}+ onChange={() => {}}+ isRequired+ isDisabled+ disabledMessage="Notifications are turned off org-wide"+ />+ </form>,+ );+ expect(container.querySelector('form')!.checkValidity()).toBe(true);+ });++ it('still blocks submission when required and off but enabled', () => {+ const {container} = render(+ <form>+ <Switch+ label="Notify"+ htmlName="notify"+ value={false}+ onChange={() => {}}+ isRequired+ />+ </form>,+ );+ expect(container.querySelector('form')!.checkValidity()).toBe(false);+ });+it('is excluded from form data when disabled, even with a disabledMessage', () => {const {container} = render(<form>diff --git a/packages/core/src/Switch/Switch.tsx b/packages/core/src/Switch/Switch.tsxindex 68cf02fadc..f02a73b5dd 100644--- a/packages/core/src/Switch/Switch.tsx+++ b/packages/core/src/Switch/Switch.tsx@@ -523,6 +523,7 @@ export function Switch({// isDisabled guard in onChange below.disabled={isDisabled && !showsDisabledMessage}aria-disabled={showsDisabledMessage ? 'true' : undefined}+ form={showsDisabledMessage ? '' : undefined}required={isRequired}onChange={e => {if (isDisabled || isBusy) {