Skip to content

Commit

Permalink
Remove value attribute for checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Sep 21, 2021
1 parent f924926 commit 5112e03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mui-material/src/internal/SwitchBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
18 changes: 18 additions & 0 deletions packages/mui-material/src/internal/SwitchBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,22 @@ describe('<SwitchBase />', () => {
]);
});
});

describe('checkbox form submission', () => {
it('dont set a void string as value', () => {
const { getByRole } = render(
<SwitchBase icon="unchecked" checkedIcon="checked" type="checkbox" />,
);

expect(getByRole('checkbox')).to.not.have.property('value', '');
});

it('allows to overwrite value', () => {
const { getByRole } = render(
<SwitchBase icon="unchecked" checkedIcon="checked" type="checkbox" value="off" />,
);

expect(getByRole('checkbox')).to.have.property('value', 'off');
});
});
});

0 comments on commit 5112e03

Please sign in to comment.