Skip to content

Commit 724010f

Browse files
committed
fix(input, file-input): refine label positioning in material theme
- Adjust label alignment and translation for outlined and placeholder states - Ensure consistent label behavior across input textarea and file-input components
1 parent 56a6e70 commit 724010f

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/components/file-input/themes/shared/file-input.material.scss

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ $theme: $material;
66
$idle-border-width: rem(1px) !default;
77
$active-border-width: rem(2px) !default;
88

9-
%label {
10-
--label-position: #{sizable(18px, 22px, 26px)};
11-
12-
transform: translateY(calc(var(--label-position) * -1));
13-
}
149

1510
%floated-styles {
1611
border-top: $idle-border-width solid transparent;
@@ -26,7 +21,6 @@ $active-border-width: rem(2px) !default;
2621
}
2722

2823
[part='label'] {
29-
@extend %label;
3024
@include type-style('caption');
3125
}
3226

@@ -65,6 +59,11 @@ $active-border-width: rem(2px) !default;
6559
right: none;
6660
}
6761
}
62+
63+
[part='label'] {
64+
translate: 0 -50%;
65+
align-self: start;
66+
}
6867
}
6968

7069
:host([outlined]:hover) {
@@ -95,12 +94,12 @@ $active-border-width: rem(2px) !default;
9594
grid-area: 1 / 3;
9695
}
9796

98-
[part='notch'] [part='label'] {
99-
transform: translateY(-73%);
100-
}
101-
10297
[part~='labelled'] [part~='file-names'] {
10398
padding-top: rem(20px);
10499
padding-bottom: rem(6px);
105100
}
101+
102+
[part='label'] {
103+
translate: 0 -73%;
104+
}
106105
}

src/components/input/themes/shared/input.material.scss

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $active-border-width: rem(2px) !default;
88
$fs: rem(16px) !default;
99

1010
%label {
11-
translate: 0 calc(var(--label-position) * -1);
11+
translate: 0 -50%;
1212
}
1313

1414
%floated-styles {
@@ -50,8 +50,8 @@ $fs: rem(16px) !default;
5050

5151
input:placeholder-shown + [part='notch'] [part='label'],
5252
[part~='filled'] + [part='notch'] [part='label'] {
53-
@extend %label;
5453
@include type-style('caption');
54+
@extend %label;
5555
}
5656

5757
[part~='input'] {
@@ -138,13 +138,33 @@ input:placeholder-shown + [part='notch'] [part='label'],
138138

139139
:host(:focus-within) {
140140
[part='label'] {
141-
@extend %label;
141+
color: var-get($theme, 'focused-secondary-color');
142+
}
143+
}
144+
145+
:host(:not([readonly]):focus-within) {
146+
[part='label'] {
142147
@include type-style('caption');
148+
}
149+
}
143150

144-
color: var-get($theme, 'focused-secondary-color');
151+
:host([outlined]) {
152+
&:has(input:placeholder-shown) {
153+
[part='label'] {
154+
align-self: start;
155+
}
156+
}
157+
}
158+
159+
:host([outlined]:not([readonly]):focus-within) {
160+
[part='label'] {
161+
@extend %label;
162+
163+
align-self: start;
145164
}
146165
}
147166

167+
148168
:host([readonly]:not([outlined]):focus-within) {
149169
:not([part~='filled']) {
150170
input:not(:placeholder-shown) + [part='notch'] [part='label'] {
@@ -245,7 +265,7 @@ input:placeholder-shown + [part='notch'] [part='label'],
245265
}
246266
}
247267

248-
[part='notch'] [part='label'] {
268+
[part='label'] {
249269
translate: 0 -73%;
250270
}
251271
}
@@ -386,8 +406,6 @@ input:placeholder-shown + [part='notch'] [part='label'],
386406
}
387407

388408
:host([outlined]) {
389-
--label-position: calc((#{var-get($theme, 'size')} / 2) - (#{$idle-border-width}));
390-
391409
[part='notch'] {
392410
border: {
393411
width: $idle-border-width;
@@ -400,6 +418,10 @@ input:placeholder-shown + [part='notch'] [part='label'],
400418

401419
[part~='filled'] + [part='notch'] {
402420
@extend %floated-styles;
421+
422+
[part='label'] {
423+
align-self: start;
424+
}
403425
}
404426
}
405427

@@ -460,10 +482,6 @@ input:placeholder-shown + [part='notch'] [part='label'],
460482
}
461483

462484
:host(:not([type='search'])[outlined]:focus-within) {
463-
[part='label'] {
464-
margin-block-start: calc(#{$active-border-width} / 2);
465-
}
466-
467485
[part='start'] {
468486
border: {
469487
color: var-get($theme, 'focused-border-color');

0 commit comments

Comments
 (0)