-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
[Checkbox][Radio] Icon font size override #21289
Comments
@samuelcolburn Thanks for reporting the issue. It comes from the usage of cloneElement that forces a value. It affects the Radio component too. What do you think of this fix? diff --git a/packages/material-ui/src/Checkbox/Checkbox.js b/packages/material-ui/src/Checkbox/Checkbox.js
index 7916091ab..6d28ca15c 100644
--- a/packages/material-ui/src/Checkbox/Checkbox.js
+++ b/packages/material-ui/src/Checkbox/Checkbox.js
@@ -64,14 +64,17 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
checkedIcon = defaultCheckedIcon,
classes,
color = 'secondary',
- icon = defaultIcon,
+ icon: iconProp = defaultIcon,
indeterminate = false,
- indeterminateIcon = defaultIndeterminateIcon,
+ indeterminateIcon: indeterminateIconProp = defaultIndeterminateIcon,
inputProps,
size = 'medium',
...other
} = props;
+ const icon = indeterminate ? indeterminateIconProp : iconProp;
+ const indeterminateIcon = indeterminate ? indeterminateIconProp : checkedIcon;
+
return (
<SwitchBase
type="checkbox"
@@ -87,11 +90,11 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
'data-indeterminate': indeterminate,
...inputProps,
}}
- icon={React.cloneElement(indeterminate ? indeterminateIcon : icon, {
- fontSize: size === 'small' ? 'small' : 'default',
+ icon={React.cloneElement(icon, {
+ fontSize: icon.props.fontSize === undefined && size !== 'medium' ? size : icon.props.fontSize,
})}
- checkedIcon={React.cloneElement(indeterminate ? indeterminateIcon : checkedIcon, {
- fontSize: size === 'small' ? 'small' : 'default',
+ checkedIcon={React.cloneElement(indeterminateIcon, {
+ fontSize: indeterminateIcon.props.fontSize === undefined && size !== 'medium' ? size : indeterminateIcon.props.fontSize
})}
ref={ref}
{...other}
@@ -171,7 +174,7 @@ Checkbox.propTypes = {
* The size of the checkbox.
* `small` is equivalent to the dense checkbox styling.
*/
- size: PropTypes.oneOf(['medium', 'small']),
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
/**
* The value of the component. The DOM API casts this to a string.
* The browser uses "on" as the default value. It's a start. Do you want to work on a pull request? :) |
@oliviertassinari I wish to work on this as my first issue if it is not taken by someone else already, thanks. |
@kn1ves Awesome, it's all yours. Note that the above fix isn't meant to be the final solution, but a proof of concept, they will be a couple of rough edges to polish :). |
When using the
icon
andcheckedIcon
props for theCheckbox
component, passing a customfontSize
doesn't change size of the icons.This issue is also present in the Checkbox demos, where the Custom Size example is the same size as all the other examples.
Current Behavior 😯
Passing a
fontSize
prop to theicon
orcustomIcon
component does nothing.Expected Behavior 🤔
Passing a valid
fontSize
prop toicon
orcustomIcon
should increase the size of theIcon
.Steps to Reproduce 🕹
Steps:
Checkbox
componenticon
orcheckedIcon
propsfontSize
Links
Sandbox with error reproduced: https://codesandbox.io/s/checkbox-issue-demo-ksr7k
Documentation section with the same error: https://material-ui.com/components/checkboxes/#checkbox-with-formcontrollabel
Context 🔦
I want to be able to customize the size of my Checkboxes. Note that other props like
color
are not overridden in the same manner.A somewhat similar issue is currently open regarding
Input
size props:#19796
Your Environment 🌎
The text was updated successfully, but these errors were encountered: