Skip to content

Commit ddb8ef8

Browse files
fix(label): use primary color on focus for md input labels (#18183)
fixes #15602
1 parent 0c83fd3 commit ddb8ef8

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

core/src/components/input/test/spec/index.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,41 @@
1515
<ion-app>
1616
<ion-content class="ion-padding">
1717
<ion-item>
18-
<ion-label position="floating">Standard</ion-label>
18+
<ion-label position="floating">Floating: input</ion-label>
1919
<ion-input></ion-input>
2020
</ion-item>
21-
<ion-item>
22-
<ion-label position="floating">Standard</ion-label>
21+
<ion-item class="item-has-focus">
22+
<ion-label position="floating">Floating: input focused value</ion-label>
2323
<ion-input value="value"></ion-input>
2424
</ion-item>
2525
<ion-item>
26-
<ion-label position="stacked">Stacked</ion-label>
26+
<ion-label position="stacked">Stacked: input</ion-label>
2727
<ion-input></ion-input>
2828
</ion-item>
2929
<ion-item>
30-
<ion-label position="stacked">Stacked</ion-label>
30+
<ion-label position="stacked">Stacked: input value</ion-label>
3131
<ion-input value="value"></ion-input>
3232
</ion-item>
3333
<ion-item>
34-
<ion-label position="floating">Floating</ion-label>
34+
<ion-label position="floating">Floating: textarea</ion-label>
3535
<ion-textarea></ion-textarea>
3636
</ion-item>
3737
<ion-item>
38-
<ion-label position="floating">Floating</ion-label>
38+
<ion-label position="floating">Floating: textarea value</ion-label>
3939
<ion-textarea value="value"></ion-textarea>
4040
</ion-item>
4141
<ion-item>
42-
<ion-label position="stacked">Stacked</ion-label>
42+
<ion-label position="stacked">Stacked: textarea</ion-label>
4343
<ion-textarea></ion-textarea>
4444
</ion-item>
45-
<ion-item>
46-
<ion-label position="stacked">Stacked</ion-label>
45+
<ion-item class="item-has-focus">
46+
<ion-label position="stacked">Stacked: textarea focused value</ion-label>
4747
<ion-textarea value="value"></ion-textarea>
4848
</ion-item>
49+
<ion-item class="custom item-has-focus">
50+
<ion-label position="stacked">Stacked: textarea focus</ion-label>
51+
<ion-textarea></ion-textarea>
52+
</ion-item>
4953

5054
</ion-content>
5155

@@ -54,6 +58,17 @@
5458
--background: #f5f5f5;
5559
}
5660

61+
.custom {
62+
--background: lightblue;
63+
}
64+
65+
.custom ion-label {
66+
color: white !important;
67+
}
68+
69+
.custom.item-has-focus ion-label {
70+
color: purple !important;
71+
}
5772
</style>
5873
</ion-app>
5974
</body>

core/src/components/item/item.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ button, a {
181181

182182
display: flex;
183183

184-
/* This is required to work with an inset highlight */
184+
// This is required to work with an inset highlight
185185
position: relative;
186186

187187
flex: 1;
@@ -261,11 +261,6 @@ button, a {
261261
flex-direction: column;
262262
}
263263

264-
// :host(.item-input-has-focus) a,
265-
// :host(.item-input-has-focus) button,
266-
// :host(.item-input-has-focus) textarea {
267-
// pointer-events: auto;
268-
// }
269264

270265
// Item Input Highlight
271266
// --------------------------------------------------
@@ -287,6 +282,7 @@ button, a {
287282
height: var(--inset-highlight-height);
288283
}
289284

285+
290286
// Item Input Focused
291287
// --------------------------------------------------
292288

core/src/components/label/label.md.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
:host(.label-stacked) {
1616
@include transform-origin(start, top);
1717
@include transform(translate3d(0, 50%, 0), scale(.75));
18+
19+
transition: color 150ms $label-md-transition-timing-function;
1820
}
1921

2022
:host(.label-floating) {
2123
@include transform(translate3d(0, 96%, 0));
2224
@include transform-origin(start, top);
2325

24-
transition: transform 150ms cubic-bezier(.4,0,.2,1);
26+
transition:
27+
color 150ms $label-md-transition-timing-function,
28+
transform 150ms $label-md-transition-timing-function;
2529
}
2630

2731
:host(.label-stacked),
@@ -39,6 +43,11 @@
3943
@include transform(translate3d(0, 50%, 0), scale(.75));
4044
}
4145

46+
:host-context(.item-has-focus).label-stacked,
47+
:host-context(.item-has-focus).label-floating {
48+
color: $label-md-text-color-focused;
49+
}
50+
4251

4352
// MD Typography
4453
// --------------------------------------------------

core/src/components/label/label.md.vars.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// --------------------------------------------------
66

77
/// @prop - Text color of the label by an input, select, or datetime
8-
$label-md-text-color: $text-color-step-600 !default;
8+
$label-md-text-color: $text-color-step-600 !default;
99

1010
/// @prop - Text color of the stacked/floating label when it is focused
11-
$label-md-text-color-focused: ion-color(primary, base) !default;
11+
$label-md-text-color-focused: ion-color(primary, base) !default;
1212

1313
/// @prop - Line height of the label when the text wraps
14-
$label-md-text-wrap-line-height: 1.5 !default;
14+
$label-md-text-wrap-line-height: 1.5 !default;
1515

16-
/// @prop - Color of the item paragraph
17-
$item-md-paragraph-text-color: $text-color-step-400 !default;
16+
/// @prop - Transition timing function of the label (stacked / focused)
17+
$label-md-transition-timing-function: cubic-bezier(.4, 0, .2, 1) !default;

0 commit comments

Comments
 (0)