-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Button] Icon Button Spacing Uneven #17494
Comments
The button has 16px of padding to the left of the text portion of the label, and to the right of the icon, I had wondered recently though whether we should support Edit: I should have double-checked the spec before commenting! The current spec now shows a button with icon (it didn't historically), and has 12px between the icon and button edge, for an 18px icon. Two more reasons we should support this usage with props... |
@una Thank you for looking at our components!
@mbrookes I agree, @fzaninotto has been advocating for it for a year now. I had this use case at a few occasions in the past, it was frustrating. I would propose diff close to this one: diff --git a/packages/material-ui/src/Button/Button.js b/packages/material-ui/src/Button/Button.js
index 4e1304ff1..ad9a0f786 100644
--- a/packages/material-ui/src/Button/Button.js
+++ b/packages/material-ui/src/Button/Button.js
@@ -179,6 +179,16 @@ export const styles = theme => ({
fullWidth: {
width: '100%',
},
+ startAdornment: {
+ display: 'inherit',
+ marginRight: 8,
+ marginLeft: -4,
+ },
+ endAdornment: {
+ display: 'inherit',
+ marginRight: -4,
+ marginLeft: 8,
+ },
});
const Button = React.forwardRef(function Button(props, ref) {
@@ -190,9 +200,11 @@ const Button = React.forwardRef(function Button(props, ref) {
component = 'button',
disabled = false,
disableFocusRipple = false,
+ endAdornment: endAdornmentProp,
focusVisibleClassName,
fullWidth = false,
size = 'medium',
+ startAdornment: startAdornmentProp,
type = 'button',
variant = 'text',
...other
@@ -223,6 +235,13 @@ const Button = React.forwardRef(function Button(props, ref) {
classNameProp,
);
+ const startAdornment = startAdornmentProp && (
+ <span className={classes.startAdornment}>{startAdornmentProp}</span>
+ );
+ const endAdornment = endAdornmentProp && (
+ <span className={classes.endAdornment}>{endAdornmentProp}</span>
+ );
+
return (
<ButtonBase
className={className}
@@ -234,7 +253,11 @@ const Button = React.forwardRef(function Button(props, ref) {
type={type}
{...other}
>
- <span className={classes.label}>{children}</span>
+ {startAdornment}
+ <span className={classes.label}>
+ {children}
+ </span>
+ {endAdornment}
</ButtonBase>
);
}); Then it can be used like this: import React from 'react';
import Button from '@material-ui/core/Button';
import CircularProgress from '@material-ui/core/CircularProgress';
export default function App() {
return (
<Button
variant="contained"
color="primary"
startAdornment={<CircularProgress color="inherit" size={20} />}
loading
>
Loading
</Button>
);
} (the loading prop would be for another pull-request) or import React from 'react';
import Button from '@material-ui/core/Button';
import DeleteIcon from '@material-ui/icons/Delete';
export default function App() {
return (
<Button
variant="contained"
color="secondary"
endAdornment={<DeleteIcon fontSize="small" />}
>
Delete
</Button>
);
} Any concern left? |
Props sound like a good idea here to adjust this style based on position. Thanks for looking into it! |
Eternal love to you if you implement icon support in material-ui 😍 |
The word "adornment? 😄 (I never really liked it for TextField, but I guess we're stuck with it now.) |
@mbrookes We could propose a change with v5. Do you have a better name in mind? It would need to be significantly better to justify a breaking change 😁. |
I was afraid you might ask that! 😆 Not specifically, and no, not worth a breaking change just to appease my personal sensibilities! |
@fzaninotto And to you if you would like to submit the PR. (Okay, perhaps not eternal... 😄) |
Current Behavior 😯
"A" spacing does not equal "B" spacing
Expected Behavior 🤔
Solution: Add
margin-right: -4px;
to icons in buttons with icon following button (adjusting "B" spacing)Steps to Reproduce 🕹
Steps:
Context 🔦
Material.io spec compliance
See also: https://material-components.github.io/material-components-web-catalog/#/component/button?type=raised
Your Environment 🌎
The text was updated successfully, but these errors were encountered: