Skip to content

Commit 33fd894

Browse files
refactor(select): set the default justify-content as a style (#29804)
- Remove the default property value in favor of setting the default style in the CSS to match the other form controls. - Updates the e2e test for `label` to remove the explicit width & add more examples with long labels and a default select without justify set.
1 parent 18b02b3 commit 33fd894

File tree

149 files changed

+56
-28
lines changed

Some content is hidden

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

149 files changed

+56
-28
lines changed

core/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ ion-select,prop,expandedIcon,string | undefined,undefined,false,false
16151615
ion-select,prop,fill,"outline" | "solid" | undefined,undefined,false,false
16161616
ion-select,prop,interface,"action-sheet" | "alert" | "popover",'alert',false,false
16171617
ion-select,prop,interfaceOptions,any,{},false,false
1618-
ion-select,prop,justify,"end" | "space-between" | "start",'space-between',false,false
1618+
ion-select,prop,justify,"end" | "space-between" | "start" | undefined,undefined,false,false
16191619
ion-select,prop,label,string | undefined,undefined,false,false
16201620
ion-select,prop,labelPlacement,"end" | "fixed" | "floating" | "stacked" | "start" | undefined,'start',false,false
16211621
ion-select,prop,mode,"ios" | "md",undefined,false,false

core/src/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,7 @@ export namespace Components {
27482748
/**
27492749
* How to pack the label and select within a line. `justify` does not apply when the label and select are on different lines when `labelPlacement` is set to `"floating"` or `"stacked"`. `"start"`: The label and select will appear on the left in LTR and on the right in RTL. `"end"`: The label and select will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and select will appear on opposite ends of the line with space between the two elements.
27502750
*/
2751-
"justify": 'start' | 'end' | 'space-between';
2751+
"justify"?: 'start' | 'end' | 'space-between';
27522752
/**
27532753
* The visible label associated with the select. Use this if you need to render a plaintext label. The `label` property will take priority over the `label` slot if both are used.
27542754
*/

core/src/components/select/select.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ button {
203203
flex-grow: 1;
204204

205205
align-items: center;
206+
justify-content: space-between;
206207

207208
height: inherit;
208209

core/src/components/select/select.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class Select implements ComponentInterface {
125125
* `"space-between"`: The label and select will appear on opposite
126126
* ends of the line with space between the two elements.
127127
*/
128-
@Prop() justify: 'start' | 'end' | 'space-between' = 'space-between';
128+
@Prop() justify?: 'start' | 'end' | 'space-between';
129129

130130
/**
131131
* The visible label associated with the select.
@@ -942,7 +942,7 @@ export class Select implements ComponentInterface {
942942
this;
943943
const mode = getIonMode(this);
944944
const hasFloatingOrStackedLabel = labelPlacement === 'floating' || labelPlacement === 'stacked';
945-
const justifyEnabled = !hasFloatingOrStackedLabel;
945+
const justifyEnabled = !hasFloatingOrStackedLabel && justify !== undefined;
946946
const rtl = isRTL(el) ? 'rtl' : 'ltr';
947947
const inItem = hostContext('ion-item', this.el);
948948
const shouldRenderHighlight = mode === 'md' && fill !== 'outline' && !inItem;

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

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,44 @@ import { expect } from '@playwright/test';
22
import { configs, test } from '@utils/test/playwright';
33

44
/**
5-
* By default ion-select only takes up
6-
* as much space as it needs. Justification is
7-
* used for when the select takes up the full
8-
* line (such as in an ion-item). As a result,
9-
* we set the width of the select so we can
10-
* see the justification results.
5+
* By default ion-select takes up the full width
6+
* of its container. The justify property can be
7+
* used to change the alignment of the select
8+
* within the container.
119
*/
1210
configs().forEach(({ title, screenshot, config }) => {
1311
test.describe(title('select: label'), () => {
12+
test.describe('select: default placement', () => {
13+
test('should render a space between justification with a default select', async ({ page }) => {
14+
await page.setContent(
15+
`
16+
<ion-select label="Label" placeholder="Select an Item"></ion-select>
17+
`,
18+
config
19+
);
20+
21+
const select = page.locator('ion-select');
22+
await expect(select).toHaveScreenshot(screenshot(`select-label-default`));
23+
});
24+
25+
test('should truncate long labels with ellipses', async ({ page }) => {
26+
await page.setContent(
27+
`
28+
<ion-select label="Long Label Long Label Long Label Long Label Long Label Long Label" placeholder="Select an Item"></ion-select>
29+
`,
30+
config
31+
);
32+
33+
const select = page.locator('ion-select');
34+
await expect(select).toHaveScreenshot(screenshot(`select-label-long-label`));
35+
});
36+
});
37+
1438
test.describe('select: start placement', () => {
1539
test('should render a start justification with label in the start position', async ({ page }) => {
1640
await page.setContent(
1741
`
18-
19-
<ion-select label="Label" placeholder="Select an Item" label-placement="start" justify="start" style="width: 200px"></ion-select>
42+
<ion-select label="Label" placeholder="Select an Item" label-placement="start" justify="start"></ion-select>
2043
`,
2144
config
2245
);
@@ -27,8 +50,7 @@ configs().forEach(({ title, screenshot, config }) => {
2750
test('should render an end justification with label in the start position', async ({ page }) => {
2851
await page.setContent(
2952
`
30-
31-
<ion-select label="Label" placeholder="Select an Item" label-placement="start" justify="end" style="width: 200px"></ion-select>
53+
<ion-select label="Label" placeholder="Select an Item" label-placement="start" justify="end"></ion-select>
3254
`,
3355
config
3456
);
@@ -39,23 +61,33 @@ configs().forEach(({ title, screenshot, config }) => {
3961
test('should render a space between justification with label in the start position', async ({ page }) => {
4062
await page.setContent(
4163
`
42-
43-
<ion-select label="Label" placeholder="Select an Item" label-placement="start" justify="space-between" style="width: 200px"></ion-select>
64+
<ion-select label="Label" placeholder="Select an Item" label-placement="start" justify="space-between"></ion-select>
4465
`,
4566
config
4667
);
4768

4869
const select = page.locator('ion-select');
4970
await expect(select).toHaveScreenshot(screenshot(`select-label-start-justify-space-between`));
5071
});
72+
73+
test('should truncate long labels with ellipses', async ({ page }) => {
74+
await page.setContent(
75+
`
76+
<ion-select label="Long Label Long Label Long Label Long Label Long Label Long Label" placeholder="Select an Item" label-placement="start" justify="start"></ion-select>
77+
`,
78+
config
79+
);
80+
81+
const select = page.locator('ion-select');
82+
await expect(select).toHaveScreenshot(screenshot(`select-label-start-justify-start-long-label`));
83+
});
5184
});
5285

5386
test.describe('select: end placement', () => {
5487
test('should render a start justification with label in the end position', async ({ page }) => {
5588
await page.setContent(
5689
`
57-
58-
<ion-select label="Label" placeholder="Select an Item" label-placement="end" justify="start" style="width: 200px"></ion-select>
90+
<ion-select label="Label" placeholder="Select an Item" label-placement="end" justify="start"></ion-select>
5991
`,
6092
config
6193
);
@@ -66,8 +98,7 @@ configs().forEach(({ title, screenshot, config }) => {
6698
test('should render an end justification with label in the end position', async ({ page }) => {
6799
await page.setContent(
68100
`
69-
70-
<ion-select label="Label" placeholder="Select an Item" label-placement="end" justify="end" style="width: 200px"></ion-select>
101+
<ion-select label="Label" placeholder="Select an Item" label-placement="end" justify="end"></ion-select>
71102
`,
72103
config
73104
);
@@ -78,8 +109,7 @@ configs().forEach(({ title, screenshot, config }) => {
78109
test('should render a space between justification with label in the end position', async ({ page }) => {
79110
await page.setContent(
80111
`
81-
82-
<ion-select label="Label" placeholder="Select an Item" label-placement="end" justify="space-between" style="width: 200px"></ion-select>
112+
<ion-select label="Label" placeholder="Select an Item" label-placement="end" justify="space-between"></ion-select>
83113
`,
84114
config
85115
);
@@ -93,8 +123,7 @@ configs().forEach(({ title, screenshot, config }) => {
93123
test('should render a start justification with label in the fixed position', async ({ page }) => {
94124
await page.setContent(
95125
`
96-
97-
<ion-select label="Label" placeholder="Select an Item" label-placement="fixed" justify="start" style="width: 200px"></ion-select>
126+
<ion-select label="Label" placeholder="Select an Item" label-placement="fixed" justify="start"></ion-select>
98127
`,
99128
config
100129
);
@@ -105,8 +134,7 @@ configs().forEach(({ title, screenshot, config }) => {
105134
test('should render an end justification with label in the fixed position', async ({ page }) => {
106135
await page.setContent(
107136
`
108-
109-
<ion-select label="Label" placeholder="Select an Item" label-placement="fixed" justify="end" style="width: 200px"></ion-select>
137+
<ion-select label="Label" placeholder="Select an Item" label-placement="fixed" justify="end"></ion-select>
110138
`,
111139
config
112140
);
@@ -117,8 +145,7 @@ configs().forEach(({ title, screenshot, config }) => {
117145
test('should render a space between justification with label in the fixed position', async ({ page }) => {
118146
await page.setContent(
119147
`
120-
121-
<ion-select label="Label" placeholder="Select an Item" label-placement="fixed" justify="space-between" style="width: 200px"></ion-select>
148+
<ion-select label="Label" placeholder="Select an Item" label-placement="fixed" justify="space-between"></ion-select>
122149
`,
123150
config
124151
);
2.74 KB
2.73 KB
2.75 KB

0 commit comments

Comments
 (0)