-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Radio] Add size="small" support #18479
Comments
@pete-lennart You can find two demos for the size small variant:
However, there is no out-of-the-box prop support. I think that we could add it. What do you think of such a diff? It could be the beginning of a pull request is you are interested :). diff --git a/docs/src/pages/components/radio-buttons/RadioButtons.tsx b/docs/src/pages/components/radio-buttons/RadioButtons.tsx
index ac30f0467..fd7ff9d72 100644
--- a/docs/src/pages/components/radio-buttons/RadioButtons.tsx
+++ b/docs/src/pages/components/radio-buttons/RadioButtons.tsx
@@ -60,8 +60,7 @@ export default function RadioButtons() {
color="default"
name="radio-button-demo"
inputProps={{ 'aria-label': 'E' }}
- icon={<RadioButtonUncheckedIcon fontSize="small" />}
- checkedIcon={<RadioButtonCheckedIcon fontSize="small" />}
+ size="small"
/>
</div>
);
diff --git a/packages/material-ui/src/Radio/Radio.d.ts b/packages/material-ui/src/Radio/Radio.d.ts
index be2d98a50..5cfeb2fde 100644
--- a/packages/material-ui/src/Radio/Radio.d.ts
+++ b/packages/material-ui/src/Radio/Radio.d.ts
@@ -7,6 +7,7 @@ export interface RadioProps
checkedIcon?: React.ReactNode;
color?: 'primary' | 'secondary' | 'default';
icon?: React.ReactNode;
+ size?: 'small' | 'medium';
}
export type RadioClassKey = SwitchBaseClassKey | 'colorPrimary' | 'colorSecondary';
diff --git a/packages/material-ui/src/Radio/Radio.js b/packages/material-ui/src/Radio/Radio.js
index 5fc1a3eb9..800d33dbd 100644
--- a/packages/material-ui/src/Radio/Radio.js
+++ b/packages/material-ui/src/Radio/Radio.js
@@ -64,6 +64,7 @@ const Radio = React.forwardRef(function Radio(props, ref) {
disabled = false,
name: nameProp,
onChange: onChangeProp,
+ size = 'medium',
...other
} = props;
const radioGroup = React.useContext(RadioGroupContext);
@@ -85,8 +86,10 @@ const Radio = React.forwardRef(function Radio(props, ref) {
<SwitchBase
color={color}
type="radio"
- icon={defaultIcon}
- checkedIcon={defaultCheckedIcon}
+ icon={React.cloneElement(defaultIcon, { fontSize: size === 'small' ? 'small' : 'default' })}
+ checkedIcon={React.cloneElement(defaultCheckedIcon, {
+ fontSize: size === 'small' ? 'small' : 'default',
+ })}
classes={{
root: clsx(classes.root, classes[`color${capitalize(color)}`]),
checked: classes.checked,
@@ -160,6 +163,11 @@ Radio.propTypes = {
* If `true`, the `input` element will be required.
*/
required: PropTypes.bool,
+ /**
+ * The size of the radio.
+ * `small` is equivalent to the dense radio styling.
+ */
+ size: PropTypes.oneOf(['small', 'medium']),
/**
* The input component prop `type`.
*/
diff --git a/packages/material-ui/src/Radio/RadioButtonIcon.js b/packages/material-ui/src/Radio/RadioButtonIcon.js
index 9cb07f681..d7e8dc464 100644
--- a/packages/material-ui/src/Radio/RadioButtonIcon.js
+++ b/packages/material-ui/src/Radio/RadioButtonIcon.js
@@ -33,26 +33,20 @@ export const styles = theme => ({
* @ignore - internal component.
*/
function RadioButtonIcon(props) {
- const { checked, classes } = props;
+ const { checked, classes, fontSize } = props;
return (
<div className={clsx(classes.root, { [classes.checked]: checked })}>
- <RadioButtonUncheckedIcon />
- <RadioButtonCheckedIcon className={classes.layer} />
+ <RadioButtonUncheckedIcon fontSize={fontSize} />
+ <RadioButtonCheckedIcon fontSize={fontSize} className={classes.layer} />
</div>
);
}
RadioButtonIcon.propTypes = { It would make it consistent with the switch size support: https://material-ui.com/components/switches/#sizes. |
Yes, that looks good! |
@pete-lennart Ok great. If you want to work on a pull request, you are free to go. |
Somebody has taken this issue? |
@SandraMarcelaHerreraArriaga Not so far. Would you like to work on it? |
Sure! Thanks :) I will start working on it |
The documentation strongly implies that Here is the code I'm using (copied from the example in the docs): <FormControl component="fieldset" >
<FormLabel component="legend">Data to display</FormLabel>
<RadioGroup
size="small"
name="dataSource"
value={dataSource}
onChange={handleDataSourceChange}
>
<FormControlLabel value="CaseCount" control={<Radio />} label="CaseCount" />
<FormControlLabel value="DeathCount" control={<Radio />} label="DeathCount" />
<FormControlLabel value="HotSpots" control={<Radio />} label="HotSpots" />
</RadioGroup>
</FormControl> Does anybody actually check to see that an issue like this actually works before closing it? I'm not trying to bust anybody's chops, I'm just trying to learn how to get my material-ui app working without spending days reverse engineering every last control of the UIX. One of my biggest challenges is discovering what parts of material-ui actually do and do not work as described in the documentation. Attached is a screenshot of the result. |
@SomervilleTom Interesting, this issue was about |
Heh. Silly me, I thought (hoped?) they were synonymous. FWIW, I did try passing |
I seem to be back at this issue. I really do want a smaller I want this design element to have a 19 pixel height (to match the standard html The devtool inspector tells me that the |
@oliviertassinari: Way cool, thanks! |
Current Behavior 😯
Property
size
is not working on component<Radio />
.Expected Behavior 🤔
The docs for the
Radio
component state thatThe
IconButton
component has a propertysize
, so settingsize
onRadio
should work as well. The typescript typings seem to be correct assize
is recognized as valid property ofRadio
.Steps to Reproduce 🕹
This sandbox demonstrates the issue. You can set
size="small"
on anIconButton
, but has no effect onRadio
.The text was updated successfully, but these errors were encountered: