diff --git a/packages/mui-material/src/Switch/Switch.js b/packages/mui-material/src/Switch/Switch.js index 6a8d98161c51b3..18e426989a38b5 100644 --- a/packages/mui-material/src/Switch/Switch.js +++ b/packages/mui-material/src/Switch/Switch.js @@ -194,6 +194,8 @@ const SwitchTrack = styled('span', { height: '100%', width: '100%', borderRadius: 14 / 2, + boxSizing: 'border-box', + border: '1px solid transparent', zIndex: -1, transition: theme.transitions.create(['opacity', 'background-color'], { duration: theme.transitions.duration.shortest, @@ -214,6 +216,8 @@ const SwitchThumb = styled('span', { memoTheme(({ theme }) => ({ boxShadow: (theme.vars || theme).shadows[1], backgroundColor: 'currentColor', + boxSizing: 'border-box', + border: '1px solid transparent', width: 20, height: 20, borderRadius: '50%', diff --git a/test/regressions/fixtures/Switch/SimpleSwitch.js b/test/regressions/fixtures/Switch/SimpleSwitch.js new file mode 100644 index 00000000000000..7b339a684d45cf --- /dev/null +++ b/test/regressions/fixtures/Switch/SimpleSwitch.js @@ -0,0 +1,12 @@ +import Switch from '@mui/material/Switch'; + +const label = { slotProps: { input: { 'aria-label': 'Switch demo' } } }; + +export default function BasicSwitches() { + return ( +
+ + +
+ ); +} diff --git a/test/regressions/index.test.js b/test/regressions/index.test.js index ee0c85c1ddc415..9ac20c214e1cfb 100644 --- a/test/regressions/index.test.js +++ b/test/regressions/index.test.js @@ -160,6 +160,21 @@ async function main() { }); }); + describe('Switch', () => { + it('should render standard variant correctly in forced-colors mode', async () => { + await page.emulateMedia({ forcedColors: 'active' }); + try { + const testcase = await renderFixture('/regression-Switch/SimpleSwitch'); + await takeScreenshot({ + testcase, + route: '/regression-Switch/SimpleSwitchForcedColors', + }); + } finally { + await page.emulateMedia({ forcedColors: 'none' }); + } + }); + }); + describe('TextField', () => { it('should render standard variant correctly in forced-colors mode', async () => { await page.emulateMedia({ forcedColors: 'active' });