From 563b883f9c486a2af8d9e3893af8e8bdb8fb73d9 Mon Sep 17 00:00:00 2001 From: sai chand <60743144+sai6855@users.noreply.github.com> Date: Thu, 31 Aug 2023 18:57:44 +0530 Subject: [PATCH] [material] Add missing classes for `Slider` `InputLabel` `InputBase` `Radio` (#38401) --- docs/pages/material-ui/api/radio.json | 2 +- docs/translations/api-docs/radio/radio.json | 5 +++++ packages/mui-material/src/InputBase/InputBase.js | 2 +- packages/mui-material/src/InputLabel/InputLabel.js | 3 ++- packages/mui-material/src/Radio/Radio.js | 4 ++-- packages/mui-material/src/Radio/Radio.test.js | 9 +++++++++ packages/mui-material/src/Radio/radioClasses.ts | 3 +++ 7 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/pages/material-ui/api/radio.json b/docs/pages/material-ui/api/radio.json index c6cc33f43ae4b1..877319f68f74fc 100644 --- a/docs/pages/material-ui/api/radio.json +++ b/docs/pages/material-ui/api/radio.json @@ -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" }, diff --git a/docs/translations/api-docs/radio/radio.json b/docs/translations/api-docs/radio/radio.json index 665544d31ffb21..ea4e514bb7ae6b 100644 --- a/docs/translations/api-docs/radio/radio.json +++ b/docs/translations/api-docs/radio/radio.json @@ -54,6 +54,11 @@ "description": "Styles applied to {{nodeName}} if {{conditions}}.", "nodeName": "the root element", "conditions": "color=\"secondary\"" + }, + "sizeSmall": { + "description": "Styles applied to {{nodeName}} if {{conditions}}.", + "nodeName": "the root element", + "conditions": "size=\"small\"" } } } diff --git a/packages/mui-material/src/InputBase/InputBase.js b/packages/mui-material/src/InputBase/InputBase.js index 90d0b3a40851ea..82a22a3b7471b0 100644 --- a/packages/mui-material/src/InputBase/InputBase.js +++ b/packages/mui-material/src/InputBase/InputBase.js @@ -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', diff --git a/packages/mui-material/src/InputLabel/InputLabel.js b/packages/mui-material/src/InputLabel/InputLabel.js index 6fe139fee107f0..f6684a35a22bb0 100644 --- a/packages/mui-material/src/InputLabel/InputLabel.js +++ b/packages/mui-material/src/InputLabel/InputLabel.js @@ -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'; @@ -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'], diff --git a/packages/mui-material/src/Radio/Radio.js b/packages/mui-material/src/Radio/Radio.js index 11be6fc28a2d0a..9d63b38de0d095 100644 --- a/packages/mui-material/src/Radio/Radio.js +++ b/packages/mui-material/src/Radio/Radio.js @@ -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 { diff --git a/packages/mui-material/src/Radio/Radio.test.js b/packages/mui-material/src/Radio/Radio.test.js index 1baac9c16566be..41a6f49919f911 100644 --- a/packages/mui-material/src/Radio/Radio.test.js +++ b/packages/mui-material/src/Radio/Radio.test.js @@ -40,6 +40,15 @@ describe('', () => { }); }); + describe('prop: size', () => { + it('add sizeSmall class to the root element when the size prop equals "small"', () => { + const { getByRole } = render(); + 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', () => { diff --git a/packages/mui-material/src/Radio/radioClasses.ts b/packages/mui-material/src/Radio/radioClasses.ts index 2d69c7f28760c9..952a87a66349ff 100644 --- a/packages/mui-material/src/Radio/radioClasses.ts +++ b/packages/mui-material/src/Radio/radioClasses.ts @@ -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; @@ -26,6 +28,7 @@ const radioClasses: RadioClasses = generateUtilityClasses('MuiRadio', [ 'disabled', 'colorPrimary', 'colorSecondary', + 'sizeSmall', ]); export default radioClasses;