Skip to content

Commit

Permalink
[Switch] Fix DOM warning when type isn't checkbox or radio (#36170
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dani-mp committed Feb 16, 2023
1 parent c3d5d38 commit ef3fb7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/mui-material/src/Switch/Switch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ describe('<Switch />', () => {
expect(getByRole('checkbox')).to.have.property('checked', false);
});

it('should not show warnings when custom `type` is provided', () => {
expect(() => render(<Switch type="submit" />)).not.toErrorDev();
});

describe('with FormControl', () => {
describe('enabled', () => {
it('should not have the disabled class', () => {
Expand Down
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 @@ -159,7 +159,7 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) {
defaultChecked={defaultChecked}
className={classes.input}
disabled={disabled}
id={hasLabelFor && id}
id={hasLabelFor ? id : undefined}
name={name}
onChange={handleInputChange}
readOnly={readOnly}
Expand Down

0 comments on commit ef3fb7e

Please sign in to comment.