Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Switch] Make color primary default #26182

Merged
merged 6 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/api-docs/switch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "union",
"description": "'default'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'<br>&#124;&nbsp;string"
},
"default": "'secondary'"
"default": "'primary'"
},
"defaultChecked": { "type": { "name": "bool" } },
"disabled": { "type": { "name": "bool" } },
Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/components/switches/ColorSwitches.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { green } from '@material-ui/core/colors';
import Switch from '@material-ui/core/Switch';

const GreenSwitch = styled(Switch)(({ theme }) => ({
'& .MuiSwitch-input.Mui-checked': {
'&.MuiSwitch-root > .Mui-checked': {
color: green[600],
'&:hover': {
backgroundColor: alpha(green[600], theme.palette.action.hoverOpacity),
},
},
'& .MuiSwitch-input.Mui-checked + .MuiSwitch-track': {
'&.MuiSwitch-root > .Mui-checked + .MuiSwitch-track': {
backgroundColor: green[600],
},
}));
Expand All @@ -21,7 +21,7 @@ export default function ColorSwitches() {
return (
<div>
<Switch {...label} defaultChecked />
<Switch {...label} defaultChecked color="primary" />
<Switch {...label} defaultChecked color="secondary" />
<Switch {...label} defaultChecked color="default" />
<GreenSwitch {...label} defaultChecked />
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/components/switches/ColorSwitches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { green } from '@material-ui/core/colors';
import Switch from '@material-ui/core/Switch';

const GreenSwitch = styled(Switch)(({ theme }) => ({
'& .MuiSwitch-input.Mui-checked': {
'&.MuiSwitch-root > .Mui-checked': {
color: green[600],
'&:hover': {
backgroundColor: alpha(green[600], theme.palette.action.hoverOpacity),
},
},
'& .MuiSwitch-input.Mui-checked + .MuiSwitch-track': {
'&.MuiSwitch-root > .Mui-checked + .MuiSwitch-track': {
backgroundColor: green[600],
},
}));
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -21,7 +21,7 @@ export default function ColorSwitches() {
return (
<div>
<Switch {...label} defaultChecked />
<Switch {...label} defaultChecked color="primary" />
<Switch {...label} defaultChecked color="secondary" />
<Switch {...label} defaultChecked color="default" />
<GreenSwitch {...label} defaultChecked />
</div>
Expand Down
7 changes: 7 additions & 0 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,13 @@ As the core components use emotion as a styled engine, the props used by emotion
}
```

- The switch color prop is now "primary" by default. To continue using the "secondary" color, you must explicitly indicate `secondary`. This brings the switch closer to the Material Design specification.

```diff
-<Switch />
+<Switch color="secondary" />
```

### Table

- The customization of the table pagination's actions labels must be done with the `getItemAriaLabel` prop. This increases consistency with the `Pagination` component.
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Switch/Switch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface SwitchProps
};
/**
* The color of the component. It supports those theme colors that make sense for this component.
* @default 'secondary'
* @default 'primary'
*/
color?: OverridableStringUnion<'primary' | 'secondary' | 'default', SwitchPropsColorOverrides>;
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Switch/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const SwitchThumb = experimentalStyled(

const Switch = React.forwardRef(function Switch(inProps, ref) {
const props = useThemeProps({ props: inProps, name: 'MuiSwitch' });
const { className, color = 'secondary', edge = false, size = 'medium', sx, ...other } = props;
const { className, color = 'primary', edge = false, size = 'medium', sx, ...other } = props;

const styleProps = {
...props,
Expand Down Expand Up @@ -259,7 +259,7 @@ Switch.propTypes /* remove-proptypes */ = {
className: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
* @default 'secondary'
* @default 'primary'
*/
color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
PropTypes.oneOf(['default', 'primary', 'secondary']),
Expand Down