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

Commit fd46483

Browse files
EladBezalelThomasBurleson
authored andcommitted
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. Closes #6740. #breaking
1 parent da53c00 commit fd46483

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
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: 43 additions & 5 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

@@ -101,6 +102,10 @@ md-input-container {
101102

102103
label:not(.md-no-float):not(.md-container-ignore),
103104
.md-placeholder {
105+
overflow: hidden;
106+
text-overflow: ellipsis;
107+
white-space: nowrap;
108+
width: 100%;
104109
order: 1;
105110
pointer-events: none;
106111
-webkit-font-smoothing: antialiased;
@@ -268,6 +273,9 @@ md-input-container {
268273
&.md-input-has-value {
269274
label:not(.md-no-float) {
270275
transform: translate3d(0, $input-label-float-offset, 0) scale($input-label-float-scale);
276+
transition: transform $swift-ease-out-timing-function 0.5s,
277+
width $swift-ease-out-timing-function 0.5s;
278+
width: calc((100% - #{$input-label-float-width}) / #{$input-label-float-scale});
271279
}
272280
}
273281

@@ -313,15 +321,27 @@ md-input-container {
313321
@include rtl(right, auto, 2px);
314322
}
315323

316-
&.md-input-focused,
317-
&.md-input-has-value {
324+
}
318325

319-
label {
320-
transform: translate3d(0, $input-label-float-offset, 0) scale($input-label-float-scale);
321-
transition: transform $swift-ease-out-timing-function 0.5s;
326+
&.md-icon-left,
327+
&.md-icon-right {
328+
> label {
329+
&:not(.md-no-float):not(.md-container-ignore),
330+
.md-placeholder {
331+
width: calc(100% - #{$icon-offset} - #{$input-label-float-width});
322332
}
323333
}
324334

335+
&.md-input-focused,
336+
&.md-input-has-placeholder,
337+
&.md-input-has-value {
338+
> label {
339+
&:not(.md-no-float):not(.md-container-ignore),
340+
.md-placeholder {
341+
width: calc((100% - #{$icon-offset} - #{$input-label-float-width}) / #{$input-label-float-scale});
342+
}
343+
}
344+
}
325345
}
326346

327347
// icon offset should have higher priority as normal label
@@ -349,6 +369,24 @@ md-input-container {
349369
&.md-icon-left.md-icon-right {
350370
padding-left: $icon-offset;
351371
padding-right: $icon-offset;
372+
373+
> label {
374+
&:not(.md-no-float):not(.md-container-ignore),
375+
.md-placeholder {
376+
width: calc(100% - (#{$icon-offset} * 2));
377+
}
378+
}
379+
380+
&.md-input-focused,
381+
&.md-input-has-placeholder,
382+
&.md-input-has-value {
383+
> label {
384+
&:not(.md-no-float):not(.md-container-ignore),
385+
.md-placeholder {
386+
width: calc((100% - (#{$icon-offset} * 2)) / #{$input-label-float-scale});
387+
}
388+
}
389+
}
352390
}
353391
}
354392

0 commit comments

Comments
 (0)