Skip to content

Commit bc3d30c

Browse files
authored
feat(select): add shapes for ionic theme (#30016)
1 parent c3a804d commit bc3d30c

File tree

40 files changed

+186
-48
lines changed

40 files changed

+186
-48
lines changed

core/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ ion-select,prop,name,string,this.inputId,false,false
20642064
ion-select,prop,okText,string,'OK',false,false
20652065
ion-select,prop,placeholder,string | undefined,undefined,false,false
20662066
ion-select,prop,selectedText,null | string | undefined,undefined,false,false
2067-
ion-select,prop,shape,"round" | undefined,undefined,false,false
2067+
ion-select,prop,shape,"rectangular" | "round" | "soft" | undefined,undefined,false,false
20682068
ion-select,prop,theme,"ios" | "md" | "ionic",undefined,false,false
20692069
ion-select,prop,toggleIcon,string | undefined,undefined,false,false
20702070
ion-select,prop,value,any,undefined,false,false

core/src/components.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,9 +3280,9 @@ export namespace Components {
32803280
*/
32813281
"selectedText"?: string | null;
32823282
/**
3283-
* The shape of the select. If "round" it will have an increased border radius.
3283+
* Set to `"soft"` for a select with slightly rounded corners, `"round"` for a select with fully rounded corners, or `"rectangular"` for a select without rounded corners. Defaults to `"round"` for the `"ionic"` theme, undefined for all other themes.
32843284
*/
3285-
"shape"?: 'round';
3285+
"shape"?: 'soft' | 'round' | 'rectangular';
32863286
/**
32873287
* The theme determines the visual appearance of the component.
32883288
*/
@@ -8704,9 +8704,9 @@ declare namespace LocalJSX {
87048704
*/
87058705
"selectedText"?: string | null;
87068706
/**
8707-
* The shape of the select. If "round" it will have an increased border radius.
8707+
* Set to `"soft"` for a select with slightly rounded corners, `"round"` for a select with fully rounded corners, or `"rectangular"` for a select without rounded corners. Defaults to `"round"` for the `"ionic"` theme, undefined for all other themes.
87088708
*/
8709-
"shape"?: 'round';
8709+
"shape"?: 'soft' | 'round' | 'rectangular';
87108710
/**
87118711
* The theme determines the visual appearance of the component.
87128712
*/

core/src/components/select/select.ionic.scss

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// TODO(ROU-10778, ROU-10875): Sync the color names to the design system of
1111
// ios and md. This will allow us to have a single color map.
1212
--border-color: #{globals.current-color(neutral)};
13-
--border-radius: #{globals.$ion-border-radius-400};
1413
--border-width: #{globals.$ion-border-size-025};
1514
--padding-start: #{globals.$ion-space-400};
1615
--padding-end: #{globals.$ion-space-400};
@@ -170,7 +169,7 @@
170169
// ----------------------------------------------------------------
171170

172171
// Disabled
173-
// ----------------------------------------------------------------
172+
// ---------------------------------------------
174173

175174
:host(.select-disabled) {
176175
--background: #{globals.$ion-primitives-neutral-100};
@@ -183,3 +182,18 @@
183182
:host(.select-disabled) .select-icon {
184183
color: globals.$ion-primitives-neutral-500;
185184
}
185+
186+
// Shapes
187+
// ----------------------------------------------------------------
188+
189+
:host(.select-shape-soft) {
190+
--border-radius: #{globals.$ion-border-radius-200};
191+
}
192+
193+
:host(.select-shape-round) {
194+
--border-radius: #{globals.$ion-border-radius-400};
195+
}
196+
197+
:host(.select-shape-rectangular) {
198+
--border-radius: #{globals.$ion-border-radius-0};
199+
}

core/src/components/select/select.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,13 @@ export class Select implements ComponentInterface {
191191
@Prop() expandedIcon?: string;
192192

193193
/**
194-
* The shape of the select. If "round" it will have an increased border radius.
194+
* Set to `"soft"` for a select with slightly rounded corners,
195+
* `"round"` for a select with fully rounded corners,
196+
* or `"rectangular"` for a select without rounded corners.
197+
*
198+
* Defaults to `"round"` for the `"ionic"` theme, undefined for all other themes.
195199
*/
196-
@Prop() shape?: 'round';
200+
@Prop() shape?: 'soft' | 'round' | 'rectangular';
197201

198202
/**
199203
* The value of the select.
@@ -990,6 +994,18 @@ export class Select implements ComponentInterface {
990994
);
991995
}
992996

997+
private getShape(): string | undefined {
998+
const theme = getIonTheme(this);
999+
const { shape } = this;
1000+
1001+
// TODO(ROU-11366): Remove theme check when shapes are defined for all themes.
1002+
if (theme === 'ionic' && shape === undefined) {
1003+
return 'round';
1004+
}
1005+
1006+
return shape;
1007+
}
1008+
9931009
/**
9941010
* Get the icon to use for the expand icon.
9951011
* If an icon is set on the component, use that.
@@ -1046,9 +1062,9 @@ export class Select implements ComponentInterface {
10461062
}
10471063

10481064
render() {
1049-
const { disabled, el, isExpanded, expandedIcon, labelPlacement, justify, placeholder, fill, shape, name, value } =
1050-
this;
1065+
const { disabled, el, isExpanded, expandedIcon, labelPlacement, justify, placeholder, fill, name, value } = this;
10511066
const theme = getIonTheme(this);
1067+
const shape = this.getShape();
10521068
const hasFloatingOrStackedLabel = labelPlacement === 'floating' || labelPlacement === 'stacked';
10531069
const shouldRenderOuterIcon = theme !== 'ionic' && hasFloatingOrStackedLabel;
10541070
const shouldRenderInnerIcon = theme === 'ionic' || !hasFloatingOrStackedLabel;

core/src/components/select/test/fill/select.e2e.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,6 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
8989
const select = page.locator('ion-select');
9090
await expect(select).toHaveScreenshot(screenshot(`select-fill-solid-label-floating`));
9191
});
92-
test('should not have visual regressions with shaped solid', async ({ page }) => {
93-
await page.setContent(
94-
`
95-
<ion-select
96-
shape="round"
97-
fill="solid"
98-
label="Fruit"
99-
value="apple"
100-
>
101-
<ion-select-option value="apple">Apple</ion-select-option>
102-
</ion-select>
103-
`,
104-
config
105-
);
106-
107-
const select = page.locator('ion-select');
108-
await expect(select).toHaveScreenshot(screenshot(`select-fill-shaped-solid`));
109-
});
11092
test('padding and border radius should be customizable', async ({ page }) => {
11193
await page.setContent(
11294
`
@@ -153,25 +135,6 @@ configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
153135
const select = page.locator('ion-select');
154136
await expect(select).toHaveScreenshot(screenshot(`select-fill-outline-label-floating`));
155137
});
156-
157-
test('should not have visual regressions with shaped outline', async ({ page }) => {
158-
await page.setContent(
159-
`
160-
<ion-select
161-
shape="round"
162-
fill="outline"
163-
label="Fruit"
164-
value="apple"
165-
>
166-
<ion-select-option value="apple">Apple</ion-select-option>
167-
</ion-select>
168-
`,
169-
config
170-
);
171-
172-
const select = page.locator('ion-select');
173-
await expect(select).toHaveScreenshot(screenshot(`select-fill-shaped-outline`));
174-
});
175138
});
176139
});
177140
});

0 commit comments

Comments
 (0)