Skip to content

Commit 6d660b7

Browse files
committed
feat(tab-button): update barge target
1 parent fb6f80c commit 6d660b7

62 files changed

Lines changed: 47 additions & 7 deletions

File tree

Some content is hidden

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

core/src/components/tab-button/tab-button.tsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,47 @@ export class TabButton implements ComponentInterface, AnchorInterface {
3434
@Element() el!: HTMLElement;
3535

3636
private badgeManager = createBadgeManager(this.el, () => {
37-
const target = this.el.querySelector(':scope > ion-icon') || this.el.querySelector('ion-label');
37+
const layout = this.layout || config.get('tabButtonLayout', 'icon-top');
38+
const hasIcon = this.hasIcon;
39+
const hasLabel = this.hasLabel;
40+
41+
// Clamp the badge if icon and label exists and layout is either `icon-top` or `icon-bottom` since the badge is positioned in the center of the button and could overlap with both the icon and label.
42+
const clamp = hasIcon && hasLabel && (layout === 'icon-top' || layout === 'icon-bottom');
43+
44+
let target: HTMLElement | null = null;
45+
46+
switch (layout) {
47+
case 'icon-top':
48+
case 'icon-bottom':
49+
if (hasIcon) {
50+
target = this.el.querySelector(':scope > ion-icon');
51+
}
52+
break;
53+
case 'icon-start':
54+
if (hasIcon && hasLabel) {
55+
target = this.el.querySelector('ion-label');
56+
} else if (hasIcon) {
57+
target = this.el.querySelector(':scope > ion-icon');
58+
}
59+
break;
60+
case 'icon-end':
61+
if (hasIcon && hasLabel) {
62+
target = this.el.querySelector(':scope > ion-icon');
63+
} else if (hasLabel) {
64+
target = this.el.querySelector('ion-label');
65+
}
66+
break;
67+
case 'icon-hide':
68+
if (hasLabel) {
69+
target = this.el.querySelector('ion-label');
70+
}
71+
break;
72+
case 'label-hide':
73+
if (hasIcon) {
74+
target = this.el.querySelector(':scope > ion-icon');
75+
}
76+
break;
77+
}
3878

3979
if (!target) {
4080
return undefined;
@@ -44,7 +84,7 @@ export class TabButton implements ComponentInterface, AnchorInterface {
4484
host: this.el,
4585
target,
4686
relativeTo: this.el.shadowRoot!.querySelector('.button-inner')!,
47-
clamp: this.hasIcon && this.hasLabel,
87+
clamp,
4888
};
4989
});
5090

core/src/components/tab-button/test/layout/tab-button.e2e.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ configs().forEach(({ title, screenshot, config }) => {
1010
<ion-tab-button tab="1" layout="icon-start">
1111
<ion-label>Recents</ion-label>
1212
<ion-icon name="call"></ion-icon>
13-
<ion-badge color="danger">12</ion-badge>
13+
<ion-badge color="danger" vertical="top" size="small">12</ion-badge>
1414
</ion-tab-button>
1515
1616
<ion-tab-button tab="2" layout="icon-start">
@@ -44,7 +44,7 @@ configs().forEach(({ title, screenshot, config }) => {
4444
<ion-tab-button tab="2" layout="icon-end">
4545
<ion-label>Favorites</ion-label>
4646
<ion-icon name="heart"></ion-icon>
47-
<ion-badge color="dark">33</ion-badge>
47+
<ion-badge color="dark" vertical="top" size="small">33</ion-badge>
4848
</ion-tab-button>
4949
5050
<ion-tab-button tab="3" layout="icon-end">
@@ -71,7 +71,7 @@ configs().forEach(({ title, screenshot, config }) => {
7171
</ion-tab-button>
7272
7373
<ion-tab-button tab="2">
74-
<ion-badge>16</ion-badge>
74+
<ion-badge vertical="top" size="small">16</ion-badge>
7575
<ion-label>Favorites</ion-label>
7676
<ion-icon name="heart"></ion-icon>
7777
</ion-tab-button>
@@ -100,7 +100,7 @@ configs().forEach(({ title, screenshot, config }) => {
100100
</ion-tab-button>
101101
102102
<ion-tab-button tab="2">
103-
<ion-badge color="danger">44</ion-badge>
103+
<ion-badge color="danger" vertical="top" size="small">44</ion-badge>
104104
<ion-icon name="heart"></ion-icon>
105105
</ion-tab-button>
106106
@@ -135,7 +135,7 @@ configs().forEach(({ title, screenshot, config }) => {
135135
<ion-tab-button tab="3" layout="icon-hide">
136136
<ion-label>Settings</ion-label>
137137
<ion-icon name="settings"></ion-icon>
138-
<ion-badge color="danger">2</ion-badge>
138+
<ion-badge color="danger" vertical="top" size="small">2</ion-badge>
139139
</ion-tab-button>
140140
</ion-tab-bar>
141141
`,
-122 Bytes
15 Bytes
127 Bytes
-120 Bytes
3 Bytes
101 Bytes
-167 Bytes
978 Bytes

0 commit comments

Comments
 (0)