close
Skip to content

[switch] Add border to make it visible in high contrast mode#48180

Merged
silviuaavram merged 4 commits intomui:masterfrom
silviuaavram:fix/switch-high-contrast
Apr 6, 2026
Merged

[switch] Add border to make it visible in high contrast mode#48180
silviuaavram merged 4 commits intomui:masterfrom
silviuaavram:fix/switch-high-contrast

Conversation

@silviuaavram
Copy link
Copy Markdown
Member

@silviuaavram silviuaavram commented Apr 2, 2026

Fixes #43479

Add transparent border to track and thumb.

Preview: https://deploy-preview-48180--material-ui.netlify.app/material-ui/react-switch/

Make sure to turn on HighContrast mode from Windows, or emulate it in Chrome.
Screenshot 2026-04-03 at 16 19 11

Before After
Screenshot 2026-04-03 at 16 19 26 Screenshot 2026-04-03 at 16 18 58

@mui-bot
Copy link
Copy Markdown

mui-bot commented Apr 2, 2026

Netlify deploy preview

https://deploy-preview-48180--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+108B(+0.02%) 🔺+16B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against e942ea8

@silviuaavram silviuaavram added accessibility a11y scope: switch Changes related to the switch. labels Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves Switch visibility in Windows/forced-colors (high contrast) mode by ensuring the control has a border that can be picked up by forced-colors rendering, and adds a visual regression check to guard the behavior.

Changes:

  • Add transparent borders to Switch track and thumb styling.
  • Add a Switch regression fixture for screenshot testing.
  • Add a Playwright visual regression screenshot in forced-colors: active mode.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/regressions/index.test.js Adds a forced-colors visual regression screenshot for Switch.
test/regressions/fixtures/Switch/SimpleSwitch.js Adds a minimal Switch fixture used by the regression runner.
packages/mui-material/src/Switch/Switch.js Adds border styling intended to make Switch visible in forced-colors/high contrast.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/mui-material/src/Switch/Switch.js
Comment thread packages/mui-material/src/Switch/Switch.js Outdated
Copy link
Copy Markdown
Member

@mj12albert mj12albert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ~ left one comment

const label = { slotProps: { input: { 'aria-label': 'Switch demo' } } };

export default function BasicSwitches() {
return <Switch {...label} />;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<>
      <Switch {...label} />
      <Switch {...label} defaultChecked />
    </>

might as well screenshot both states ~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this test is useful. Is it testing the high contrast specifically? If not, it should be removed because we already have a lot of switch demos as visual regression

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used by the test below to test the high contrast mode. I did the same for StandardTextField previously, to test high contrast for that variant. Is there another way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I did not know that the pattern exist. 👍

@silviuaavram silviuaavram added v7.x needs cherry-pick The PR should be cherry-picked to master after merge. labels Apr 6, 2026
@silviuaavram silviuaavram merged commit 3f1a610 into mui:master Apr 6, 2026
21 checks passed
@silviuaavram silviuaavram deleted the fix/switch-high-contrast branch April 6, 2026 13:19
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

Cherry-pick PRs will be created targeting branches: v7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y needs cherry-pick The PR should be cherry-picked to master after merge. scope: switch Changes related to the switch. v7.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Switch] Not visible in high contrast mode

6 participants