From 5112e034ca87e599aad262253ce38de791141e9b Mon Sep 17 00:00:00 2001 From: garronej Date: Sat, 18 Sep 2021 16:03:10 +0200 Subject: [PATCH] Remove value attribute for checkbox --- .../mui-material/src/internal/SwitchBase.js | 2 +- .../src/internal/SwitchBase.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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..5bd65c098d968f 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')).to.not.have.property('value', ''); + }); + + it('allows to overwrite value', () => { + const { getByRole } = render( + , + ); + + expect(getByRole('checkbox')).to.have.property('value', 'off'); + }); + }); });