Skip to content

Commit a0d5ad7

Browse files
fix(button): update styling for badge (#30414)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? Some stylings for the ion-badge when slotted in an ion-button were missing. ## What is the new behavior? Updated the styling for the ion-badge when slotted in an ion-button according to the designs: - Adjusted badge padding; - Abandoned the `:has` pseudo-selector for a simple 'button-had-badge' class; - Adjusted font-size for icons inside the button; - Adjusted badge positioning according to button size and badge length. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
1 parent 8b5215f commit a0d5ad7

File tree

49 files changed

+118
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+118
-25
lines changed

core/src/components/badge/badge.ionic.scss

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,12 @@
160160
// Badge in Button
161161
// --------------------------------------------------
162162

163-
:host([vertical]:not(.in-tab-button).in-button.badge-small) {
164-
@include globals.position(null, calc(-1 * var(globals.$ion-space-050)));
165-
}
166-
167-
:host([vertical]:not(.in-tab-button).in-button.badge-medium),
168-
:host([vertical]:not(.in-tab-button).in-button.badge-large) {
169-
@include globals.position(null, globals.$ion-space-050);
170-
}
171-
172163
:host(:not(:empty).in-button) {
164+
--padding-start: #{globals.$ion-scale-050};
165+
--padding-end: #{globals.$ion-scale-050};
166+
173167
@include globals.typography(globals.$ion-body-action-xs);
168+
174169
min-width: globals.$ion-scale-400;
175170
height: globals.$ion-scale-400;
176171

core/src/components/badge/badge.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Badge implements ComponentInterface {
8080
const theme = getIonTheme(this);
8181
const { size } = this;
8282

83-
// TODO(ROU-10747): Remove theme check when sizes are defined for all themes.
83+
// TODO(FW-6355): Remove theme check when sizes are defined for all themes.
8484
if (theme !== 'ionic') {
8585
return undefined;
8686
}
@@ -133,6 +133,7 @@ export class Badge implements ComponentInterface {
133133
[`badge-vertical-${this.vertical}`]: this.vertical !== undefined,
134134
'in-button': hostContext('ion-button', this.el),
135135
'in-tab-button': hostContext('ion-tab-button', this.el),
136+
'long-badge': (this.el.textContent?.trim().length ?? 0) > 2,
136137
})}
137138
>
138139
<slot></slot>

core/src/components/badge/test/hint/badge.e2e.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,13 @@ configs({ directions: ['ltr'], modes: ['md', 'ios', 'ionic-md'] }).forEach(({ co
5656

5757
await expect(container).toHaveScreenshot(screenshot(`badge-hint-button-bottom`));
5858
});
59+
60+
test('should not have visual regressions for different button sizes', async ({ page }) => {
61+
await page.goto('/src/components/badge/test/hint', config);
62+
63+
const container = page.locator('#button-size');
64+
65+
await expect(container).toHaveScreenshot(screenshot(`badge-hint-button-size`));
66+
});
5967
});
6068
});
68 Bytes
30 Bytes
87 Bytes
4.57 KB
6.67 KB
5.52 KB
6.26 KB

0 commit comments

Comments
 (0)