Skip to content

Commit 861b4bf

Browse files
feat(tab-button): add the shape property and styles for the ionic theme (#30057)
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? Tab button does not have a shape property. ## What is the new behavior? - Adds support for the shape property in tab button. - Adds styles for the "soft", "round" and "rectangular" shapes in the ionic theme - Defaults the shape to "round" for the ionic theme - Adds an e2e test for shape with screenshots of all shapes ## 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 e16c633 commit 861b4bf

23 files changed

+161
-6
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,7 @@ ion-tab-button,prop,layout,"icon-bottom" | "icon-end" | "icon-hide" | "icon-star
22132213
ion-tab-button,prop,mode,"ios" | "md",undefined,false,false
22142214
ion-tab-button,prop,rel,string | undefined,undefined,false,false
22152215
ion-tab-button,prop,selected,boolean,false,false,false
2216+
ion-tab-button,prop,shape,"rectangular" | "round" | "soft" | undefined,undefined,false,false
22162217
ion-tab-button,prop,tab,string | undefined,undefined,false,false
22172218
ion-tab-button,prop,target,string | undefined,undefined,false,false
22182219
ion-tab-button,prop,theme,"ios" | "md" | "ionic",undefined,false,false

core/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,10 @@ export namespace Components {
35043504
* The selected tab component
35053505
*/
35063506
"selected": boolean;
3507+
/**
3508+
* Set to `"soft"` for a tab-button with slightly rounded corners, `"round"` for a tab-button with fully rounded corners, or `"rectangular"` for a tab-button without rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
3509+
*/
3510+
"shape"?: 'soft' | 'round' | 'rectangular';
35073511
/**
35083512
* A tab id must be provided for each `ion-tab`. It's used internally to reference the selected tab or by the router to switch between them.
35093513
*/
@@ -8941,6 +8945,10 @@ declare namespace LocalJSX {
89418945
* The selected tab component
89428946
*/
89438947
"selected"?: boolean;
8948+
/**
8949+
* Set to `"soft"` for a tab-button with slightly rounded corners, `"round"` for a tab-button with fully rounded corners, or `"rectangular"` for a tab-button without rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
8950+
*/
8951+
"shape"?: 'soft' | 'round' | 'rectangular';
89448952
/**
89458953
* A tab id must be provided for each `ion-tab`. It's used internally to reference the selected tab or by the router to switch between them.
89468954
*/
560 Bytes
Loading
540 Bytes
Loading
658 Bytes
Loading
584 Bytes
Loading
590 Bytes
Loading
666 Bytes
Loading

core/src/components/tab-button/tab-button.ionic.scss

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
--focus-ring-color: #{globals.$ion-border-focus-default};
99
--focus-ring-width: #{globals.$ion-border-radius-025};
1010

11-
@include globals.border-radius(globals.$ion-border-radius-200);
12-
1311
align-content: center;
1412

1513
min-height: globals.$ion-scale-1200;
@@ -73,3 +71,18 @@
7371
width: globals.$ion-scale-600;
7472
height: globals.$ion-scale-600;
7573
}
74+
75+
// Tab Button Shapes
76+
// -------------------------------------------------------------------------------
77+
78+
:host(.tab-button-shape-soft) {
79+
@include globals.border-radius(globals.$ion-border-radius-200);
80+
}
81+
82+
:host(.tab-button-shape-round) {
83+
@include globals.border-radius(globals.$ion-border-radius-400);
84+
}
85+
86+
:host(.tab-button-shape-rectangular) {
87+
@include globals.border-radius(globals.$ion-border-radius-0);
88+
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ export class TabButton implements ComponentInterface, AnchorInterface {
6868
*/
6969
@Prop({ mutable: true }) selected = false;
7070

71+
/**
72+
* Set to `"soft"` for a tab-button with slightly rounded corners,
73+
* `"round"` for a tab-button with fully rounded corners, or `"rectangular"`
74+
* for a tab-button without rounded corners.
75+
*
76+
* Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
77+
*/
78+
@Prop() shape?: 'soft' | 'round' | 'rectangular';
79+
7180
/**
7281
* A tab id must be provided for each `ion-tab`. It's used internally to reference
7382
* the selected tab or by the router to switch between them.
@@ -107,6 +116,22 @@ export class TabButton implements ComponentInterface, AnchorInterface {
107116
}
108117
}
109118

119+
private getShape(): string | undefined {
120+
const theme = getIonTheme(this);
121+
const { shape } = this;
122+
123+
// TODO(ROU-11436): Remove theme check when shapes are defined for all themes.
124+
if (theme !== 'ionic') {
125+
return undefined;
126+
}
127+
128+
if (shape === undefined) {
129+
return 'round';
130+
}
131+
132+
return shape;
133+
}
134+
110135
private selectTab(ev: Event | KeyboardEvent) {
111136
if (this.tab !== undefined) {
112137
if (!this.disabled) {
@@ -141,6 +166,7 @@ export class TabButton implements ComponentInterface, AnchorInterface {
141166
render() {
142167
const { disabled, hasIcon, hasLabel, href, rel, target, layout, selected, tab, inheritedAttributes } = this;
143168
const theme = getIonTheme(this);
169+
const shape = this.getShape();
144170
const attrs = {
145171
download: this.download,
146172
href,
@@ -164,6 +190,7 @@ export class TabButton implements ComponentInterface, AnchorInterface {
164190
[`tab-layout-${layout}`]: true,
165191
'ion-activatable': true,
166192
'ion-selectable': true,
193+
[`tab-button-shape-${shape}`]: shape !== undefined,
167194
'ion-focusable': true,
168195
}}
169196
>

0 commit comments

Comments
 (0)