startIcon, endIcon button position
See original GitHub issueThe startIcon, endIcons option in buttons is a necessary addition. But I must say, I’m not crazy with the way it was implemented “after” “before” the children.
I realize that the Material Design specification puts the icon next to the text. In my opinion, one of the fails of this spec. Most designers would position the icon on the edge of the button. Because it just looks better.
This is not intuitively achievable with the implementation material-ui chose. The icon is positioned inside the label which means that any padding you apply to the button forces the icon inward. Leaving you with absolute position override or negative margin.
An absolute override is difficult, bc you are forced to apply the extract space you lose positioning absolutely manually and since the icon and the text are directly next to eachother, is only possible by manually adding a span to the button text. Which sucks.
Negative margin does work, but since it affects the rest of the space as well requires you to specify the margins depending on the type of button.
- [x ] The issue is present in the latest release.
- [ x] I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
As described above
Expected Behavior 🤔
There are a few options to make the behavior more easily customizable. Absolute positioning seems to me the best option for this, and it should be easy to apply
- place the icon outside the label. This way, you can use absolute positioning and select the sibling label element to compensate for lost space. You can still do this “before / after”
- place a span around the text inside the label. Same as above. However, prob not desirable since it changes the dom structure either for all or for just this case
Steps to Reproduce 🕹
| Tech | Version |
|---|---|
| Material-UI | v4.5.0 |
| React | 16.9 |
| Browser | chrome |
| TypeScript | no |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:14 (6 by maintainers)
Top Related StackOverflow Question
Regarding absolute positioning, it actually didn’t take too much code to align this nicely:
Not sure if this was ever revived in another issue but I’m a bit surprised this isn’t something that’s being considered.
Take for example this custom “checkbox” button group I have using buttons with an
endIcon:To me it’s crystal clear it would be good to be able to align the icon to the edge of each button, it would make for a much nicer UI.