Skip to content

Commit cad1c61

Browse files
fix(select): update icon color and use correct focused class (#30342)
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? <!-- Please describe the current behavior that you are modifying. --> There are a few items to note: - Styles are using a non-existing focus class. It currently uses `.has-focus` which isn't being used anywhere within `select.tsx`. It seems that `.has-focus` comes a copy and paste that wasn't updated. - Icon uses the highlight color when expanded, in item, and no fill. This leads to the styling looking weird compared to when it's not in an item especially since labels do not change colors. Only applies to `md` mode. | List no lines | List with lines | | --- | ----------- | | ![Screenshot 2025-04-07 at 1 01 14 PM](https://github.com/user-attachments/assets/e310e5e8-d0bc-4976-b623-c8db358307c8) | ![Screenshot 2025-04-07 at 1 01 31 PM](https://github.com/user-attachments/assets/d4c0776d-cd5d-48a1-95a3-42b74e3dd767) | - The focus without a validation status does not update the border correctly when inside an item and has a solid fill. Only applies to `md` mode. | Outside item | Inside item | |--------|--------| | ![Screenshot 2025-04-07 at 1 07 13 PM](https://github.com/user-attachments/assets/ee8c4fff-630d-4f7c-b3c5-f9daf22ff7d4) | ![Screenshot 2025-04-07 at 1 08 45 PM](https://github.com/user-attachments/assets/046d69fc-823e-4fa4-a19f-f8e641874b4d) | ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Styles are now using the correct focus class: `.has-focus`, removing `ion-focused`. - If the select is inside an item and has no fill then the icon will not use the highlight color. Only applies to `md` mode. | List no lines | List with lines | | --- | ----------- | | ![Screenshot 2025-04-07 at 1 13 17 PM](https://github.com/user-attachments/assets/0e6fd28e-4925-4799-a24b-8e21348eb168) | ![Screenshot 2025-04-07 at 1 14 11 PM](https://github.com/user-attachments/assets/adec2576-27d9-4150-8e60-8af5fa9cc012) | - The focus without a validation status uses the highlight color when inside an item and has a solid fill. Only applies to `md` mode. | Outside item | Inside item | |--------|--------| | ![Screenshot 2025-04-07 at 1 07 13 PM](https://github.com/user-attachments/assets/ee8c4fff-630d-4f7c-b3c5-f9daf22ff7d4) | ![Screenshot 2025-04-07 at 1 16 47 PM](https://github.com/user-attachments/assets/bc8b03b9-6ad1-40b0-a7fd-3f6e654ec066) | ## 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. --> Dev build: `8.5.4-dev.11744743162.1ec9251d` Select cannot have a focused class and an expanded class at the same time. It's one or the other. --------- Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>
1 parent d52fca0 commit cad1c61

File tree

57 files changed

+453
-117
lines changed

Some content is hidden

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

57 files changed

+453
-117
lines changed

‎core/src/components/input/input.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ export class Input implements ComponentInterface {
5050
* Resets when the input loses focus.
5151
*/
5252
private didInputClearOnEdit = false;
53+
5354
/**
5455
* The value of the input when the input is focused.
5556
*/
5657
private focusedValue?: string | number | null;
5758

59+
/**
60+
* The `hasFocus` state ensures the focus class is
61+
* added regardless of how the element is focused.
62+
* The `ion-focused` class only applies when focused
63+
* via tabbing, not by clicking.
64+
* The `has-focus` logic was added to ensure the class
65+
* is applied in both cases.
66+
*/
5867
@State() hasFocus = false;
5968

6069
@Element() el!: HTMLIonInputElement;

‎core/src/components/select/select.md.outline.scss

+16-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* the select is focused.
4444
*/
4545
:host(.select-fill-outline.select-expanded),
46-
:host(.select-fill-outline.ion-focused) {
46+
:host(.select-fill-outline.has-focus) {
4747
--border-width: var(--highlight-height);
4848
--border-color: var(--highlight-color);
4949
}
@@ -240,3 +240,18 @@
240240
:host(.label-floating.select-fill-outline) .select-outline-notch {
241241
border-top: none;
242242
}
243+
244+
// Select Icon
245+
// ----------------------------------------------------------------
246+
247+
/**
248+
* When the select has an outline fill and
249+
* in an item, then the icon should
250+
* take on the highlight color.
251+
*/
252+
:host(.in-item.select-expanded.select-fill-outline) .select-wrapper .select-icon,
253+
:host(.in-item.has-focus.select-fill-outline) .select-wrapper .select-icon,
254+
:host(.in-item.has-focus.ion-valid.select-fill-outline) .select-wrapper .select-icon,
255+
:host(.in-item.ion-touched.ion-invalid.select-fill-outline) .select-wrapper .select-icon {
256+
color: var(--highlight-color);
257+
}

‎core/src/components/select/select.md.scss

+24-12
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
--highlight-height: 2px;
1313
}
1414

15-
.select-icon {
16-
width: $select-md-icon-size;
17-
18-
transition: transform .15s cubic-bezier(.4, 0, .2, 1);
19-
20-
color: #{$text-color-step-500};
21-
}
22-
2315
// Select Label
2416
// ----------------------------------------------------------------
2517

@@ -29,9 +21,9 @@
2921
* only apply to floating or stacked labels.
3022
*/
3123
:host(.select-label-placement-floating.select-expanded) .label-text-wrapper,
32-
:host(.select-label-placement-floating.ion-focused) .label-text-wrapper,
24+
:host(.select-label-placement-floating.has-focus) .label-text-wrapper,
3325
:host(.select-label-placement-stacked.select-expanded) .label-text-wrapper,
34-
:host(.select-label-placement-stacked.ion-focused) .label-text-wrapper {
26+
:host(.select-label-placement-stacked.has-focus) .label-text-wrapper {
3527
color: var(--highlight-color);
3628
}
3729

@@ -61,7 +53,7 @@
6153
}
6254

6355
:host(.select-expanded) .select-highlight,
64-
:host(.ion-focused) .select-highlight {
56+
:host(.has-focus) .select-highlight {
6557
transform: scale(1);
6658
}
6759

@@ -77,6 +69,14 @@
7769
// Select Icon
7870
// ----------------------------------------------------------------
7971

72+
.select-icon {
73+
width: $select-md-icon-size;
74+
75+
transition: transform .15s cubic-bezier(.4, 0, .2, 1);
76+
77+
color: #{$select-md-icon-color};
78+
}
79+
8080
/**
8181
* This rotates the chevron icon
8282
* when the select is activated.
@@ -86,6 +86,18 @@
8686
@include transform(rotate(180deg));
8787
}
8888

89+
/**
90+
* When the select has no fill and
91+
* in an item, then the icon should
92+
* be the same color as the text color.
93+
*/
94+
:host(.in-item.select-expanded) .select-wrapper .select-icon,
95+
:host(.in-item.has-focus) .select-wrapper .select-icon,
96+
:host(.in-item.has-focus.ion-valid) .select-wrapper .select-icon,
97+
:host(.in-item.ion-touched.ion-invalid) .select-wrapper .select-icon {
98+
color: #{$select-md-icon-color};
99+
}
100+
89101
/**
90102
* When the select is focused the icon should
91103
* take on the highlight color.
@@ -95,7 +107,7 @@
95107
:host(.select-expanded) .select-wrapper .select-icon,
96108
:host(.has-focus.ion-valid) .select-wrapper .select-icon,
97109
:host(.ion-touched.ion-invalid) .select-wrapper .select-icon,
98-
:host(.ion-focused) .select-wrapper .select-icon {
110+
:host(.has-focus) .select-wrapper .select-icon {
99111
color: var(--highlight-color);
100112
}
101113

‎core/src/components/select/select.md.solid.scss

+18-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* If the select has a validity state, the
2828
* border should reflect that as a color.
2929
*/
30+
:host(.select-expanded.select-fill-solid.ion-valid),
3031
:host(.has-focus.select-fill-solid.ion-valid),
3132
:host(.select-fill-solid.ion-touched.ion-invalid) {
3233
--border-color: var(--highlight-color);
@@ -56,9 +57,9 @@
5657
* much darker on focus.
5758
*/
5859
:host(.select-fill-solid.select-expanded),
59-
:host(.select-fill-solid.ion-focused) {
60+
:host(.select-fill-solid.has-focus) {
6061
--background: #{$background-color-step-150};
61-
--border-color: #{$background-color-step-750};
62+
--border-color: var(--highlight-color);
6263
}
6364

6465
:host(.select-fill-solid) .select-wrapper {
@@ -79,3 +80,18 @@
7980
*/
8081
max-width: calc(100% / #{$form-control-label-stacked-scale});
8182
}
83+
84+
// Select Icon
85+
// ----------------------------------------------------------------
86+
87+
/**
88+
* When the select has a solid fill and
89+
* in an item, then the icon should
90+
* take on the highlight color.
91+
*/
92+
:host(.in-item.select-expanded.select-fill-solid) .select-wrapper .select-icon,
93+
:host(.in-item.has-focus.select-fill-solid) .select-wrapper .select-icon,
94+
:host(.in-item.has-focus.ion-valid.select-fill-solid) .select-wrapper .select-icon,
95+
:host(.in-item.ion-touched.ion-invalid.select-fill-solid) .select-wrapper .select-icon {
96+
color: var(--highlight-color);
97+
}

‎core/src/components/select/select.md.vars.scss

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
/// @prop - Size of the select icon
88
$select-md-icon-size: dynamic-font(13px);
9+
10+
/// @prop - Color of the select icon
11+
$select-md-icon-color: $text-color-step-500;
12+
913
/// @prop - The amount of whitespace to display on either side of the floating label
1014
$select-md-floating-label-padding: 4px;
1115

‎core/src/components/select/select.scss

+6-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
pointer-events: none;
8989
}
9090

91-
:host(.ion-focused) button {
91+
:host(.has-focus) button {
9292
border: 2px solid #5e9ed6;
9393
}
9494

@@ -308,7 +308,9 @@ button {
308308
* highlight when the select is blurred.
309309
*/
310310
:host(.has-focus.ion-valid),
311-
:host(.ion-touched.ion-invalid) {
311+
:host(.select-expanded.ion-valid),
312+
:host(.ion-touched.ion-invalid),
313+
:host(.select-expanded.ion-touched.ion-invalid) {
312314
--border-color: var(--highlight-color);
313315
}
314316

@@ -320,7 +322,7 @@ button {
320322
* present on the select. Otherwise the helper text should
321323
* be shown.
322324
*/
323-
.select-bottom .error-text {
325+
.select-bottom .error-text {
324326
display: none;
325327

326328
color: var(--highlight-color-invalid);
@@ -597,7 +599,7 @@ button {
597599
* :host(.label-floating.select-label-placement-floating) .native-wrapper .select-placeholder
598600
*/
599601
:host(.select-expanded.select-label-placement-floating) .native-wrapper .select-placeholder,
600-
:host(.ion-focused.select-label-placement-floating) .native-wrapper .select-placeholder,
602+
:host(.has-focus.select-label-placement-floating) .native-wrapper .select-placeholder,
601603
:host(.has-value.select-label-placement-floating) .native-wrapper .select-placeholder {
602604
opacity: 1;
603605
}

‎core/src/components/select/select.tsx

+30-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ export class Select implements ComponentInterface {
7171

7272
@State() isExpanded = false;
7373

74+
/**
75+
* The `hasFocus` state ensures the focus class is
76+
* added regardless of how the element is focused.
77+
* The `ion-focused` class only applies when focused
78+
* via tabbing, not by clicking.
79+
* The `has-focus` logic was added to ensure the class
80+
* is applied in both cases.
81+
*/
82+
@State() hasFocus = false;
83+
7484
/**
7585
* The text to display on the cancel button.
7686
*/
@@ -852,10 +862,14 @@ export class Select implements ComponentInterface {
852862
};
853863

854864
private onFocus = () => {
865+
this.hasFocus = true;
866+
855867
this.ionFocus.emit();
856868
};
857869

858870
private onBlur = () => {
871+
this.hasFocus = false;
872+
859873
this.ionBlur.emit();
860874
};
861875

@@ -1090,8 +1104,20 @@ export class Select implements ComponentInterface {
10901104
}
10911105

10921106
render() {
1093-
const { disabled, el, isExpanded, expandedIcon, labelPlacement, justify, placeholder, fill, shape, name, value } =
1094-
this;
1107+
const {
1108+
disabled,
1109+
el,
1110+
isExpanded,
1111+
expandedIcon,
1112+
labelPlacement,
1113+
justify,
1114+
placeholder,
1115+
fill,
1116+
shape,
1117+
name,
1118+
value,
1119+
hasFocus,
1120+
} = this;
10951121
const mode = getIonMode(this);
10961122
const hasFloatingOrStackedLabel = labelPlacement === 'floating' || labelPlacement === 'stacked';
10971123
const justifyEnabled = !hasFloatingOrStackedLabel && justify !== undefined;
@@ -1137,6 +1163,8 @@ export class Select implements ComponentInterface {
11371163
'has-value': hasValue,
11381164
'label-floating': labelShouldFloat,
11391165
'has-placeholder': placeholder !== undefined,
1166+
'has-focus': hasFocus,
1167+
// TODO(FW-6451): Remove `ion-focusable` class in favor of `has-focus`.
11401168
'ion-focusable': true,
11411169
[`select-${rtl}`]: true,
11421170
[`select-fill-${fill}`]: fill !== undefined,

‎core/src/components/select/test/basic/select.e2e.ts

+46
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,49 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
324324
});
325325
});
326326
});
327+
328+
/**
329+
* focus has a consistent behavior across modes
330+
*/
331+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
332+
test.describe(title('select: focus'), () => {
333+
test('should have the focus class when tabbing', async ({ page, pageUtils }) => {
334+
await page.setContent(
335+
`
336+
<ion-select aria-label="Fruit" interface="alert">
337+
<ion-select-option value="apple">Apple</ion-select-option>
338+
</ion-select>
339+
`,
340+
config
341+
);
342+
343+
const select = page.locator('ion-select');
344+
345+
await pageUtils.pressKeys('Tab');
346+
await expect(select).toHaveClass(/has-focus/);
347+
});
348+
349+
test('should have the focus class after clicking to close', async ({ page }) => {
350+
await page.setContent(
351+
`
352+
<ion-select aria-label="Fruit" interface="alert">
353+
<ion-select-option value="apple">Apple</ion-select-option>
354+
</ion-select>
355+
`,
356+
config
357+
);
358+
359+
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
360+
const select = page.locator('ion-select');
361+
const alert = page.locator('ion-alert');
362+
const confirmButton = alert.locator('.alert-button:not(.alert-button-role-cancel)');
363+
364+
await select.click();
365+
await ionAlertDidPresent.next();
366+
367+
await confirmButton.click();
368+
369+
await expect(select).toHaveClass(/has-focus/);
370+
});
371+
});
372+
});

‎core/src/components/select/test/color/select.e2e.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
77
test('should set label and highlight color on expand', async ({ page }) => {
88
await page.setContent(
99
`
10-
<ion-select label="Label" class="select-expanded" value="apple" class="ion-focused" color="danger">
10+
<ion-select label="Label" class="select-expanded" value="apple" class="has-focus" color="danger">
1111
<ion-select-option value="apple">Apple</ion-select-option>
1212
</ion-select>
1313
`,
@@ -22,7 +22,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
2222
test('should set label and highlight color on expand', async ({ page }) => {
2323
await page.setContent(
2424
`
25-
<ion-select fill="solid" label="Label" class="select-expanded" value="apple" class="ion-focused" color="danger">
25+
<ion-select fill="solid" label="Label" class="select-expanded" value="apple" class="has-focus" color="danger">
2626
<ion-select-option value="apple">Apple</ion-select-option>
2727
</ion-select>
2828
`,
@@ -37,7 +37,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
3737
test('should set label and highlight color on expand', async ({ page }) => {
3838
await page.setContent(
3939
`
40-
<ion-select fill="outline" label="Label" class="select-expanded" value="apple" class="ion-focused" color="danger">
40+
<ion-select fill="outline" label="Label" class="select-expanded" value="apple" class="has-focus" color="danger">
4141
<ion-select-option value="apple">Apple</ion-select-option>
4242
</ion-select>
4343
`,

0 commit comments

Comments
 (0)