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

[core] Normalize usage of pseudo classes selectors #25748

Merged
merged 4 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/material-ui/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const AutocompleteRoot = experimentalStyled(
},
)(({ styleProps }) => ({
/* Styles applied to the root element. */
[`&.Mui-focused .${autocompleteClasses.clearIndicator}`]: {
[`&.${autocompleteClasses.focused} .${autocompleteClasses.clearIndicator}`]: {
visibility: 'visible',
},
/* Avoid double tap issue on iOS */
Expand Down Expand Up @@ -351,7 +351,7 @@ const AutocompleteListbox = experimentalStyled(
opacity: theme.palette.action.disabledOpacity,
pointerEvents: 'none',
},
'&.Mui-focusVisible': {
[`&.${autocompleteClasses.focusVisible}`]: {
backgroundColor: theme.palette.action.focus,
},
'&[aria-selected="true"]': {
Expand All @@ -366,7 +366,7 @@ const AutocompleteListbox = experimentalStyled(
backgroundColor: theme.palette.action.selected,
},
},
'&.Mui-focusVisible': {
[`&.${autocompleteClasses.focusVisible}`]: {
backgroundColor: alpha(
theme.palette.primary.main,
theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const autocompleteClasses = generateUtilityClasses('MuiAutocomplete', [
'root',
'fullWidth',
'focused',
'focusVisible',
'tag',
'tagSizeSmall',
'tagSizeMedium',
Expand Down
8 changes: 4 additions & 4 deletions packages/material-ui/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ const ButtonRoot = experimentalStyled(
boxShadow: theme.shadows[8],
}),
},
'&.Mui-focusVisible': {
[`&.${buttonClasses.focusVisible}`]: {
...(styleProps.variant === 'contained' && {
boxShadow: theme.shadows[6],
}),
},
'&.Mui-disabled': {
[`&.${buttonClasses.disabled}`]: {
color: theme.palette.action.disabled,
...(styleProps.variant === 'outlined' && {
border: `1px solid ${theme.palette.action.disabledBackground}`,
Expand Down Expand Up @@ -246,13 +246,13 @@ const ButtonRoot = experimentalStyled(
'&:hover': {
boxShadow: 'none',
},
'&.Mui-focusVisible': {
[`&.${buttonClasses.focusVisible}`]: {
boxShadow: 'none',
},
'&:active': {
boxShadow: 'none',
},
'&.Mui-disabled': {
[`&.${buttonClasses.disabled}`]: {
boxShadow: 'none',
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useForkRef from '../utils/useForkRef';
import useEventCallback from '../utils/useEventCallback';
import useIsFocusVisible from '../utils/useIsFocusVisible';
import TouchRipple from './TouchRipple';
import { getButtonBaseUtilityClass } from './buttonBaseClasses';
import buttonBaseClasses, { getButtonBaseUtilityClass } from './buttonBaseClasses';

const overridesResolver = (props, styles) => styles.root || {};

Expand Down Expand Up @@ -58,7 +58,7 @@ export const ButtonBaseRoot = experimentalStyled(
'&::-moz-focus-inner': {
borderStyle: 'none', // Remove Firefox dotted outline.
},
'&.Mui-disabled': {
[`&.${buttonBaseClasses.disabled}`]: {
pointerEvents: 'none', // Disable link interactions
cursor: 'default',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/ButtonGroup/ButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ const ButtonGroupRoot = experimentalStyled(
...(styleProps.variant === 'contained' &&
styleProps.orientation === 'horizontal' && {
borderRight: `1px solid ${theme.palette.grey[400]}`,
'&.Mui-disabled': {
[`&.${buttonGroupClasses.disabled}`]: {
borderRight: `1px solid ${theme.palette.action.disabled}`,
},
}),
...(styleProps.variant === 'contained' &&
styleProps.orientation === 'vertical' && {
borderBottom: `1px solid ${theme.palette.grey[400]}`,
'&.Mui-disabled': {
[`&.${buttonGroupClasses.disabled}`]: {
borderBottom: `1px solid ${theme.palette.action.disabled}`,
},
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/CardActionArea/CardActionArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CardActionAreaRoot = experimentalStyled(
opacity: 0,
},
},
[`&.Mui-focusVisible .${cardActionAreaClasses.focusHighlight}`]: {
[`&.${cardActionAreaClasses.focusVisible} .${cardActionAreaClasses.focusHighlight}`]: {
opacity: theme.palette.action.focusOpacity,
},
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const CheckboxRoot = experimentalStyled(
color: theme.palette.text.secondary,
/* Styles applied to the root element unless `color="default"`. */
...(styleProps.color !== 'default' && {
[`&.Mui-checked, &.${checkboxClasses.indeterminate}`]: {
[`&.${checkboxClasses.checked}, &.${checkboxClasses.indeterminate}`]: {
color: theme.palette[styleProps.color].main,
'&:hover': {
backgroundColor: alpha(
Expand All @@ -65,7 +65,7 @@ const CheckboxRoot = experimentalStyled(
},
},
},
'&.Mui-disabled': {
[`&.${checkboxClasses.disabled}`]: {
color: theme.palette.action.disabled,
},
}),
Expand Down
14 changes: 7 additions & 7 deletions packages/material-ui/src/Chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const ChipRoot = experimentalStyled(
padding: 0, // Remove `button` padding
verticalAlign: 'middle',
boxSizing: 'border-box',
'&.Mui-disabled': {
[`&.${chipClasses.disabled}`]: {
opacity: theme.palette.action.disabledOpacity,
pointerEvents: 'none',
},
Expand Down Expand Up @@ -194,7 +194,7 @@ const ChipRoot = experimentalStyled(
}),
/* Styles applied to the root element if `onDelete` is defined. */
...(styleProps.onDelete && {
'&.Mui-focusVisible': {
[`&.${chipClasses.focusVisible}`]: {
backgroundColor: alpha(
theme.palette.action.selected,
theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity,
Expand All @@ -204,7 +204,7 @@ const ChipRoot = experimentalStyled(
/* Styles applied to the root element if `onDelete` and not `color="default"` is defined. */
...(styleProps.onDelete &&
styleProps.color !== 'default' && {
'&.Mui-focusVisible': {
[`&.${chipClasses.focusVisible}`]: {
backgroundColor: theme.palette[styleProps.color].dark,
},
}),
Expand All @@ -222,7 +222,7 @@ const ChipRoot = experimentalStyled(
theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity,
),
},
'&.Mui-focusVisible': {
[`&.${chipClasses.focusVisible}`]: {
backgroundColor: alpha(
theme.palette.action.selected,
theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity,
Expand All @@ -235,7 +235,7 @@ const ChipRoot = experimentalStyled(
/* Styles applied to the root element if `onClick` and not `color="default"` is defined or `clickable={true}`. */
...(styleProps.clickable &&
styleProps.color !== 'default' && {
'&:hover, &.Mui-focusVisible': {
[`&:hover, &.${chipClasses.focusVisible}`]: {
backgroundColor: theme.palette[styleProps.color].dark,
},
}),
Expand All @@ -250,7 +250,7 @@ const ChipRoot = experimentalStyled(
[`&.${chipClasses.clickable}:hover`]: {
backgroundColor: theme.palette.action.hover,
},
'&.Mui-focusVisible': {
[`&.${chipClasses.focusVisible}`]: {
backgroundColor: theme.palette.action.focus,
},
[`& .${chipClasses.avatar}`]: {
Expand Down Expand Up @@ -283,7 +283,7 @@ const ChipRoot = experimentalStyled(
theme.palette.action.hoverOpacity,
),
},
'&.Mui-focusVisible': {
[`&.${chipClasses.focusVisible}`]: {
backgroundColor: alpha(
theme.palette[styleProps.color].main,
theme.palette.action.focusOpacity,
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Fab/Fab.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ const FabRoot = experimentalStyled(
},
textDecoration: 'none',
},
'&.Mui-focusVisible': {
[`&.${fabClasses.focusVisible}`]: {
boxShadow: theme.shadows[6],
},
'&.Mui-disabled': {
[`&.${fabClasses.disabled}`]: {
color: theme.palette.action.disabled,
boxShadow: theme.shadows[0],
backgroundColor: theme.palette.action.disabledBackground,
Expand Down
14 changes: 7 additions & 7 deletions packages/material-ui/src/FilledInput/FilledInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled
import InputBase from '../InputBase';
import experimentalStyled, { shouldForwardProp } from '../styles/experimentalStyled';
import useThemeProps from '../styles/useThemeProps';
import { getFilledInputUtilityClass } from './filledInputClasses';
import filledInputClasses, { getFilledInputUtilityClass } from './filledInputClasses';
import {
overridesResolver as inputBaseOverridesResolver,
InputBaseRoot,
Expand Down Expand Up @@ -55,10 +55,10 @@ const FilledInputRoot = experimentalStyled(
backgroundColor,
},
},
'&.Mui-focused': {
[`&.${filledInputClasses.focused}`]: {
backgroundColor,
},
'&.Mui-disabled': {
[`&.${filledInputClasses.disabled}`]: {
backgroundColor: light ? 'rgba(0, 0, 0, 0.12)' : 'rgba(255, 255, 255, 0.12)',
},
...(!styleProps.disableUnderline && {
Expand All @@ -77,10 +77,10 @@ const FilledInputRoot = experimentalStyled(
}),
pointerEvents: 'none', // Transparent to the hover style.
},
'&.Mui-focused:after': {
[`&.${filledInputClasses.focused}:after`]: {
transform: 'scaleX(1)',
},
'&.Mui-error:after': {
[`&.${filledInputClasses.error}:after`]: {
borderBottomColor: theme.palette.error.main,
transform: 'scaleX(1)', // error is always underlined in red
},
Expand All @@ -97,10 +97,10 @@ const FilledInputRoot = experimentalStyled(
}),
pointerEvents: 'none', // Transparent to the hover style.
},
'&:hover:not(.Mui-disabled):before': {
[`&:hover:not(.${filledInputClasses.disabled}):before`]: {
borderBottom: `1px solid ${theme.palette.text.primary}`,
},
'&.Mui-disabled:before': {
[`&.${filledInputClasses.disabled}:before`]: {
borderBottomStyle: 'dotted',
},
}),
Expand Down
9 changes: 8 additions & 1 deletion packages/material-ui/src/FilledInput/filledInputClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ export function getFilledInputUtilityClass(slot) {
return generateUtilityClass('MuiFilledInput', slot);
}

const filledInputClasses = generateUtilityClasses('MuiFilledInput', ['root', 'underline', 'input']);
const filledInputClasses = generateUtilityClasses('MuiFilledInput', [
'root',
'focused',
'disabled',
'error',
'underline',
'input',
]);

export default filledInputClasses;
1 change: 1 addition & 0 deletions packages/material-ui/src/FormControl/formControlClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const formControlClasses = generateUtilityClasses('MuiFormControl', [
'marginNormal',
'marginDense',
'fullWidth',
'disabled',
]);

export default formControlClasses;
4 changes: 2 additions & 2 deletions packages/material-ui/src/FormControlLabel/FormControlLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const FormControlLabelRoot = experimentalStyled(
WebkitTapHighlightColor: 'transparent',
marginLeft: -11,
marginRight: 16, // used for row presentation of radio/checkbox
'&.Mui-disabled': {
[`&.${formControlLabelClasses.disabled}`]: {
cursor: 'default',
},
...(styleProps.labelPlacement === 'start' && {
Expand All @@ -64,7 +64,7 @@ export const FormControlLabelRoot = experimentalStyled(
marginLeft: 16,
}),
[`& .${formControlLabelClasses.label}`]: {
'&.Mui-disabled': {
[`&.${formControlLabelClasses.disabled}`]: {
color: theme.palette.text.disabled,
},
},
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui/src/FormHelperText/FormHelperText.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import formControlState from '../FormControl/formControlState';
import useFormControl from '../FormControl/useFormControl';
import experimentalStyled from '../styles/experimentalStyled';
import capitalize from '../utils/capitalize';
import { getFormHelperTextUtilityClasses } from './formHelperTextClasses';
import formHelperTextClasses, { getFormHelperTextUtilityClasses } from './formHelperTextClasses';
import useThemeProps from '../styles/useThemeProps';

const overridesResolver = (props, styles) => {
Expand Down Expand Up @@ -53,10 +53,10 @@ const FormHelperTextRoot = experimentalStyled(
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
'&.Mui-disabled': {
[`&.${formHelperTextClasses.disabled}`]: {
color: theme.palette.text.disabled,
},
'&.Mui-error': {
[`&.${formHelperTextClasses.error}`]: {
color: theme.palette.error.main,
},
...(styleProps.size === 'small' && {
Expand Down
8 changes: 4 additions & 4 deletions packages/material-ui/src/FormLabel/FormLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export const FormLabelRoot = experimentalStyled(
...theme.typography.body1,
lineHeight: '1.4375em',
padding: 0,
'&.Mui-focused': {
[`&.${formLabelClasses.focused}`]: {
color: theme.palette[styleProps.color].main,
},
'&.Mui-disabled': {
[`&.${formLabelClasses.disabled}`]: {
color: theme.palette.text.disabled,
},
'&.Mui-error': {
[`&.${formLabelClasses.error}`]: {
color: theme.palette.error.main,
},
}));
Expand All @@ -66,7 +66,7 @@ const AsteriskComponent = experimentalStyled(
{},
{ name: 'MuiFormLabel', slot: 'Asterisk' },
)(({ theme }) => ({
'&.Mui-error': {
[`&.${formLabelClasses.error}`]: {
color: theme.palette.error.main,
},
}));
Expand Down
10 changes: 5 additions & 5 deletions packages/material-ui/src/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { deepmerge, refType } from '@material-ui/utils';
import InputBase from '../InputBase';
import experimentalStyled, { shouldForwardProp } from '../styles/experimentalStyled';
import useThemeProps from '../styles/useThemeProps';
import { getInputUtilityClass } from './inputClasses';
import inputClasses, { getInputUtilityClass } from './inputClasses';
import {
overridesResolver as inputBaseOverridesResolver,
InputBaseRoot,
Expand Down Expand Up @@ -64,10 +64,10 @@ const InputRoot = experimentalStyled(
}),
pointerEvents: 'none', // Transparent to the hover style.
},
'&.Mui-focused:after': {
[`&.${inputClasses.focused}:after`]: {
transform: 'scaleX(1)',
},
'&.Mui-error:after': {
[`&.${inputClasses.error}:after`]: {
borderBottomColor: theme.palette.error.main,
transform: 'scaleX(1)', // error is always underlined in red
},
Expand All @@ -84,14 +84,14 @@ const InputRoot = experimentalStyled(
}),
pointerEvents: 'none', // Transparent to the hover style.
},
'&:hover:not(.Mui-disabled):before': {
[`&:hover:not(.${inputClasses.disabled}):before`]: {
borderBottom: `2px solid ${theme.palette.text.primary}`,
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
borderBottom: `1px solid ${bottomLineColor}`,
},
},
'&.Mui-disabled:before': {
[`&.${inputClasses.disabled}:before`]: {
borderBottomStyle: 'dotted',
},
}),
Expand Down
9 changes: 8 additions & 1 deletion packages/material-ui/src/Input/inputClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ export function getInputUtilityClass(slot) {
return generateUtilityClass('MuiInput', slot);
}

const inputClasses = generateUtilityClasses('MuiInput', ['root', 'underline', 'input']);
const inputClasses = generateUtilityClasses('MuiInput', [
'root',
'focused',
'error',
'disabled',
'underline',
'input',
]);

export default inputClasses;
Loading