Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 09ee338

Browse files
committed
fix(input): truncate long label
* Truncating the label if it's longer than the input itself * When the input is focused the label is responsive to its width change fixes #5331
1 parent 74fe691 commit 09ee338

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/components/input/demoBasicUsage/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</md-input-container>
3636

3737
<md-input-container class="md-block" flex-gt-sm>
38-
<label>Last Name</label>
38+
<label>Long Last Name That Will Be Truncated And 3 Dots (Ellipsis) Will Appear At The End</label>
3939
<input ng-model="theMax">
4040
</md-input-container>
4141
</div>

src/components/input/input.scss

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $input-label-default-offset: 24px !default;
44
$input-label-default-scale: 1.0 !default;
55
$input-label-float-offset: 6px !default;
66
$input-label-float-scale: 0.75 !default;
7+
$input-label-float-width: $input-container-padding + 16px;
78

89
$input-placeholder-offset: $input-label-default-offset !default;
910

@@ -100,11 +101,28 @@ md-input-container {
100101
> label {
101102
@include rtl(left, $icon-offset, auto);
102103
@include rtl(right, auto, $icon-offset);
104+
105+
&:not(.md-no-float):not(.md-container-ignore),
106+
.md-placeholder {
107+
width: calc(100% - #{$icon-offset} - #{$input-label-float-width});
108+
}
109+
}
110+
111+
&.md-input-focused,
112+
&.md-input-has-placeholder,
113+
&.md-input-has-value {
114+
label:not(.md-no-float) {
115+
width: calc((100% - #{$icon-offset} - #{$input-label-float-width}) / #{$input-label-float-scale});
116+
}
103117
}
104118
}
105119

106120
label:not(.md-no-float):not(.md-container-ignore),
107121
.md-placeholder {
122+
overflow: hidden;
123+
text-overflow: ellipsis;
124+
white-space: nowrap;
125+
width: 100%;
108126
order: 1;
109127
pointer-events: none;
110128
-webkit-font-smoothing: antialiased;
@@ -272,6 +290,9 @@ md-input-container {
272290
&.md-input-has-value {
273291
label:not(.md-no-float) {
274292
transform: translate3d(0, $input-label-float-offset, 0) scale($input-label-float-scale);
293+
transition: transform $swift-ease-out-timing-function 0.5s,
294+
width $swift-ease-out-timing-function 0.5s;
295+
width: calc((100% - #{$input-label-float-width})/ #{$input-label-float-scale});
275296
}
276297
}
277298

@@ -317,16 +338,6 @@ md-input-container.md-icon-float {
317338
@include rtl(left, 2px, auto);
318339
@include rtl(right, auto, 2px);
319340
}
320-
321-
&.md-input-focused,
322-
&.md-input-has-value {
323-
324-
label {
325-
transform: translate3d(0, $input-label-float-offset, 0) scale($input-label-float-scale);
326-
transition: transform $swift-ease-out-timing-function 0.5s;
327-
}
328-
}
329-
330341
}
331342

332343
md-input-container.md-icon-right {

0 commit comments

Comments
 (0)