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
Changes from all 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
@@ -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" } },
6 changes: 3 additions & 3 deletions docs/src/pages/components/switches/ColorSwitches.js
Original file line number Diff line number Diff line change
@@ -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-switchBase.Mui-checked': {
color: green[600],
'&:hover': {
backgroundColor: alpha(green[600], theme.palette.action.hoverOpacity),
},
},
'& .MuiSwitch-input.Mui-checked + .MuiSwitch-track': {
'& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track': {
backgroundColor: green[600],
},
}));
@@ -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>
6 changes: 3 additions & 3 deletions docs/src/pages/components/switches/ColorSwitches.tsx
Original file line number Diff line number Diff line change
@@ -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-switchBase.Mui-checked': {
color: green[600],
'&:hover': {
backgroundColor: alpha(green[600], theme.palette.action.hoverOpacity),
},
},
'& .MuiSwitch-input.Mui-checked + .MuiSwitch-track': {
'& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track': {
backgroundColor: green[600],
},
}));
@@ -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>
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
@@ -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.
2 changes: 1 addition & 1 deletion packages/material-ui/src/Switch/Switch.d.ts
Original file line number Diff line number Diff line change
@@ -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>;
/**
4 changes: 2 additions & 2 deletions packages/material-ui/src/Switch/Switch.js
Original file line number Diff line number Diff line change
@@ -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,
@@ -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']),