From 5b6406c22ce2b700fae7a34b561e55b0aed86c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Mon, 13 Feb 2023 18:09:49 +0100 Subject: [PATCH 1/2] Fix DOM warning when using Switch with type other than checkbox or radio --- packages/mui-material/src/internal/SwitchBase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mui-material/src/internal/SwitchBase.js b/packages/mui-material/src/internal/SwitchBase.js index fb488c20617638..b2242deb86f4db 100644 --- a/packages/mui-material/src/internal/SwitchBase.js +++ b/packages/mui-material/src/internal/SwitchBase.js @@ -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} From ffde56d3430f70b4247bbf547c340c50a121a39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Wed, 15 Feb 2023 12:46:03 +0100 Subject: [PATCH 2/2] Add test for Switch with type submit --- packages/mui-material/src/Switch/Switch.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/mui-material/src/Switch/Switch.test.js b/packages/mui-material/src/Switch/Switch.test.js index 1c9a99278c1f89..9f362d8dbcf296 100644 --- a/packages/mui-material/src/Switch/Switch.test.js +++ b/packages/mui-material/src/Switch/Switch.test.js @@ -92,6 +92,10 @@ describe('', () => { expect(getByRole('checkbox')).to.have.property('checked', false); }); + it('should not show warnings when custom `type` is provided', () => { + expect(() => render()).not.toErrorDev(); + }); + describe('with FormControl', () => { describe('enabled', () => { it('should not have the disabled class', () => {