Skip to content

Commit

Permalink
[material] Add missing classes for Slider InputLabel InputBase
Browse files Browse the repository at this point in the history
…`Radio` (mui#38401)
  • Loading branch information
sai6855 authored and mnajdova committed Sep 8, 2023
1 parent 60b1b18 commit 7acf90e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/pages/material-ui/api/radio.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"name": "Radio",
"imports": ["import Radio from '@mui/material/Radio';", "import { Radio } from '@mui/material';"],
"styles": {
"classes": ["root", "checked", "disabled", "colorPrimary", "colorSecondary"],
"classes": ["root", "checked", "disabled", "colorPrimary", "colorSecondary", "sizeSmall"],
"globalClasses": { "checked": "Mui-checked", "disabled": "Mui-disabled" },
"name": "MuiRadio"
},
Expand Down
5 changes: 5 additions & 0 deletions docs/translations/api-docs/radio/radio.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>color=\"secondary\"</code>"
},
"sizeSmall": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>size=\"small\"</code>"
}
}
}
2 changes: 1 addition & 1 deletion packages/mui-material/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const useUtilityClasses = (ownerState) => {
fullWidth && 'fullWidth',
focused && 'focused',
formControl && 'formControl',
size === 'small' && 'sizeSmall',
size && size !== 'medium' && `size${capitalize(size)}`,
multiline && 'multiline',
startAdornment && 'adornedStart',
endAdornment && 'adornedEnd',
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material/src/InputLabel/InputLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import formControlState from '../FormControl/formControlState';
import useFormControl from '../FormControl/useFormControl';
import FormLabel, { formLabelClasses } from '../FormLabel';
import useThemeProps from '../styles/useThemeProps';
import capitalize from '../utils/capitalize';
import styled, { rootShouldForwardProp } from '../styles/styled';
import { getInputLabelUtilityClasses } from './inputLabelClasses';

Expand All @@ -18,7 +19,7 @@ const useUtilityClasses = (ownerState) => {
formControl && 'formControl',
!disableAnimation && 'animated',
shrink && 'shrink',
size === 'small' && 'sizeSmall',
size && size !== 'normal' && `size${capitalize(size)}`,
variant,
],
asterisk: [required && 'asterisk'],
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/Radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import radioClasses, { getRadioUtilityClass } from './radioClasses';
import styled, { rootShouldForwardProp } from '../styles/styled';

const useUtilityClasses = (ownerState) => {
const { classes, color } = ownerState;
const { classes, color, size } = ownerState;

const slots = {
root: ['root', `color${capitalize(color)}`],
root: ['root', `color${capitalize(color)}`, size !== 'medium' && `size${capitalize(size)}`],
};

return {
Expand Down
9 changes: 9 additions & 0 deletions packages/mui-material/src/Radio/Radio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe('<Radio />', () => {
});
});

describe('prop: size', () => {
it('add sizeSmall class to the root element when the size prop equals "small"', () => {
const { getByRole } = render(<Radio size="small" />);
const radio = getByRole('radio');
const root = radio.parentElement;
expect(root).to.have.class(classes.sizeSmall);
});
});

describe('with FormControl', () => {
describe('enabled', () => {
it('should not have the disabled class', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/mui-material/src/Radio/radioClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface RadioClasses {
colorPrimary: string;
/** Styles applied to the root element if `color="secondary"`. */
colorSecondary: string;
/** Styles applied to the root element if `size="small"`. */
sizeSmall: string;
}

export type RadioClassKey = keyof RadioClasses;
Expand All @@ -26,6 +28,7 @@ const radioClasses: RadioClasses = generateUtilityClasses('MuiRadio', [
'disabled',
'colorPrimary',
'colorSecondary',
'sizeSmall',
]);

export default radioClasses;

0 comments on commit 7acf90e

Please sign in to comment.