-
-
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
[IconButton] Implement a new edge prop #14758
[IconButton] Implement a new edge prop #14758
Conversation
Details of bundle changes.Comparing: 099bc5e...c81bf03
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you apply the new prop to every search result you posted? The description implies it's common with multiple search result but the solution is only applied to a single instance.
@jedwards1211 Why do you want to make the IconButton own the logic responsible for a correct layout within a Toolbar? Shouldn't it be the other way around? |
Well because the IconButton itself affects layout. If it didn't have any margin I would agree. However by moving the logic inside the IconButton we can safely adjust the margin without affect layout because layout isn't hardcoded but done semantically. |
@eps1lon I see, thanks for clarifying it. What do you think of a single boolean flag prop that that also works with the size property? We could name it .anti-padding {
margin: -12px;
}
.anti-padding-small {
margin: -3px
} I think that this strategy can cover more use case, it sounds great to me. |
I'm not sure negative margin in all directions would work flawlessly in all cases. Maybe... I'll give it a try, it may mess up the vertical alignment though. |
@eps1lon yes definitely, I'll update the other places in the demos, I just wanted to wait to do that work till I knew this would be accepted, we've agreed on the API |
@oliviertassinari okay, unfortunately |
antiPadding for me does not clearly convey what the property is supposed to do |
@joshwooding I agree; I think |
@jedwards1211 Ok, my bad, poor proposition. Instead, could we rely on CSS first & last child selectors? |
@oliviertassinari I think if that were a flexible enough approach it would have already been done by whomever added the 12px padding to <AppBar>
My App
<AlertIconButtons />
<AccountIconButtons />
</AppBar> Where |
@jedwards1211 If I had to guess, I would say that I'm the one who added the negative margin. We have never spend any effort into improving this implement. Maybe we can find something better given the field has been little explored yet. But no, I can't think of anything better, somebody else? I like the property proposition. Regarding the naming. What do you think of? edge?: 'start' | 'end' | false; |
This comment has been minimized.
This comment has been minimized.
@oliviertassinari did you mean to post your last message on my other PR? Anyway thanks! So are you saying you want me to put the padding fixes into this PR? |
As far as using the ListItem directly, unfortunately it breaks encapsulation in some cases (the list is in a separate component that extra stuff like the inputs can't or shouldn't be passed into) |
We should be careful with that given
|
@eps1lon Is right, better move carefully. We can split the effort into different pull requests. I think that the first order of business is to abstract the negative margin styles. |
Okay I renamed the prop to |
* side of the icon with content above or below, without ruining the border | ||
* size and shape). | ||
*/ | ||
edge: PropTypes.oneOf(['left', 'right', false]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of start | end
? It's an open question, I'm not sure what's best.
On our codebase
- We are using the following values for the InputAdornment component:
position: PropTypes.oneOf(['start', 'end']),
- We are using the following values for the FormControlLabel component:
labelPlacement: PropTypes.oneOf(['end', 'start', 'top', 'bottom']),
- We are using the following values for the Tooltip component:
placement: PropTypes.oneOf([
'bottom-end',
'bottom-start',
'bottom',
'left-end',
'left-start',
'left',
'right-end',
'right-start',
'right',
'top-end',
'top-start',
'top',
]),
- Everywhere else we use
left | right
.
Benchmarking
CSS specification
- The align-items CSS property uses the following values:
align-items?: 'flex-start' | 'flex-end' | 'center' | 'baseline'
I'm wondering if the CSS property values were influenced by RTL considerations or if it's simply related to the flew direction that can be either the x or y axis. Ok, it's probably not a good example, let me look deeper.
- The CSS Grid model seems to have replace the left right concepts with start end: https://css-tricks.com/snippets/css/complete-guide-grid/.
Misc
cc @mui-org/core-contributors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, does Toolbar
automatically reverse its content in RTL mode? If so then maybe you're right that we should reverse the margin applied by edge
in RTL mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Toolbar automatically reverse its content in RTL mode?
Yes, it does, you can try it on https://next.material-ui.com/. I'm trying to understand what would be more idiomatic to our users. I believe very few of them care about RTL. Hence my question, it's not obvious to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will change the enum to start | end
then. I think it is probably most convenient if this prop does the same thing conceptually in RTL mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me there's enough precedent for users understanding start | end
, even though it's a bit less obvious than left | right
for InputAdornment
and so forth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari oh, so looks like a JSS plugin is used to automatically flip all left and right properties in RTL mode and I don't need to check for RTL mode in my code changes -- am I understanding correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start | end
👍
A related issue: #14784. |
and use it in all the appropriate places I can find in the demos
a8949fa
to
165ee99
Compare
165ee99
to
0e5f3be
Compare
0e5f3be
to
c81bf03
Compare
This is great. |
@KenGregory please help me advocate for adding an |
@jedwards1211 Thanks |
Thank you guys! |
One of the most common things we all have to do with
IconButton
s is applymarginLeft: -12
ormarginRight: -12
to counteract the padding and fix the icon's horizontal alignment with content above or below. (It's common in your demos too)It gets a bit tedious to fix every case with JSS styles. Let's make it easier for ourselves! ✨
With this PR,
<IconButton align="left">
will applymarginLeft: -12
andalign="right"
will applymarginRight: -12
. Forsize="small"
, it will use-3
for the margin instead.