diff --git a/packages/mui-material/src/internal/SwitchBase.js b/packages/mui-material/src/internal/SwitchBase.js index d55af9a606fc50..f0dbae62e76664 100644 --- a/packages/mui-material/src/internal/SwitchBase.js +++ b/packages/mui-material/src/internal/SwitchBase.js @@ -168,7 +168,7 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) { ownerState={ownerState} tabIndex={tabIndex} type={type} - value={value} + {...(type === 'checkbox' && value === undefined ? {} : { value })} {...inputProps} /> {checked ? checkedIcon : icon} diff --git a/packages/mui-material/src/internal/SwitchBase.test.js b/packages/mui-material/src/internal/SwitchBase.test.js index 5b6c0a5ce8c183..fd5742ed00429e 100644 --- a/packages/mui-material/src/internal/SwitchBase.test.js +++ b/packages/mui-material/src/internal/SwitchBase.test.js @@ -434,4 +434,22 @@ describe('', () => { ]); }); }); + + describe('checkbox form submission', () => { + it('dont set a void string as value', () => { + const { getByRole } = render( + , + ); + + expect(getByRole('checkbox')).not.to.have.property('value', ''); + }); + + it('allows to overwrite value', () => { + const { getByRole } = render( + , + ); + + expect(getByRole('checkbox')).to.have.property('value', 'off'); + }); + }); });