Repository navigation
feat(button): improve badge spacing and stacking #31647
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
Changes from all commits
408f69b
cdd1add
025dc92
dd3ef66
15b2ee0
4823b85
2c4d695
419d5cd
122c48c
59c8d26
8ea6ea2
30f2bfa
e3b9d06
ff71f79
a65efc6
ccaf44a
9aafc40
c39e117
06c1d44
f8f0a48
e939128
6cc5546
cd55b40
f6742bc
c8db919
6a8940f
ded6629
cfbc970
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -473,6 +473,42 @@ $spinner-sizes: xsmall, small, medium, large, xlarge; | |
| // Button: With a Badge | ||
| // -------------------------------------------------- | ||
|
|
||
| // A badge can overflow its button, so the button sits above its siblings to keep the badge visible | ||
| :host(.button-has-badge) { | ||
| position: relative; | ||
|
|
||
| z-index: 1; | ||
| } | ||
|
|
||
| :host(.button-has-badge) .button-native { | ||
| overflow: visible; | ||
| } | ||
|
|
||
| @each $size in $sizes { | ||
| // The badge overlaps the vertical padding, so a badge taller than the label doesn't make the button taller than its min height. | ||
| // The block margins fall back to 0px because no theme sets them, and calc() needs a unit. | ||
| :host(.button-size-#{$size}:not(.button-has-icon-only)) ::slotted(ion-badge:not([vertical])) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A badge in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gave start-slot badges swapped inline margins in 6a8940f, so the gap is now between the badge and the label. The |
||
| @include mixins.margin( | ||
| calc( | ||
| var(--ion-button-size-#{$size}-badge-margin-top, 0px) - | ||
| var(--padding-top, var(--ion-button-size-#{$size}-padding-top, 0px)) | ||
| ), | ||
| var(--ion-button-size-#{$size}-badge-margin-end), | ||
| calc( | ||
| var(--ion-button-size-#{$size}-badge-margin-bottom, 0px) - | ||
| var(--padding-bottom, var(--ion-button-size-#{$size}-padding-bottom, 0px)) | ||
| ), | ||
| var(--ion-button-size-#{$size}-badge-margin-start) | ||
| ); | ||
| } | ||
|
|
||
| // A badge before the label keeps the gap on the label's side | ||
| :host(.button-size-#{$size}:not(.button-has-icon-only)) ::slotted(ion-badge[slot="start"]:not([vertical])) { | ||
| @include mixins.margin( | ||
| null, | ||
| var(--ion-button-size-#{$size}-badge-margin-start), | ||
| null, | ||
| var(--ion-button-size-#{$size}-badge-margin-end) | ||
| ); | ||
| } | ||
| } | ||
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.
Dropping the vertical padding for the whole button hits badge buttons whose label wraps or scales up. With a two-line label in a 140px
expand="block"button, the text ends up 3px from the top and bottom edges, where the same button without a badge keeps 7px. Could the compensation go on the badge instead, like a negative block margin on::slotted(ion-badge:not([vertical]))? The label would keep its padding, and buttons with averticalbadge wouldn't lose it either.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.
Good call, moved it to the badge in c8db919. The button keeps its padding, and a badge without a
verticalposition gets negative block margins equal to that padding, so a tall badge still doesn't make the button taller than its min height. Your wrappedexpand="block"example now keeps 7px, andverticalbadges keep the padding too.The
badge.margintopandbottomtokens add to those negative margins, so custom themes can still adjust them. No theme sets them, and they fall back to0px, since an unset or unitless value would make thecalc()invalid. The other zero margins in the button tokens now usevar(--ion-spacing-0)(ded6629).