Skip to content

Commit 6e3c0c3

Browse files
committed
fix(input): make start and end hints interact well when their text needs to wrap
1 parent b1e5ff6 commit 6e3c0c3

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

src/demo-app/input/input-demo.html

+9
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ <h4>Textarea</h4>
221221
<md-hint align="end">{{hintLabelWithCharCount.value.length}}</md-hint>
222222
</md-input-container>
223223
</p>
224+
<p>
225+
<md-input-container style="margin-bottom: 4em">
226+
<textarea mdInput #longHint placeholder="Enter text to count"></textarea>
227+
<md-hint>
228+
Enter some text to count how many characters are in it. The character count is shown on the right.
229+
</md-hint>
230+
<md-hint align="end" style="white-space: nowrap">Length: {{longHint.value.length}}</md-hint>
231+
</md-input-container>
232+
</p>
224233
<p>
225234
<md-checkbox [(ngModel)]="color">Check to change the color:</md-checkbox>
226235
<md-input-container [color]="color ? 'primary' : 'accent'">

src/lib/input/input-container.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
<div class="mat-input-hint-wrapper" *ngSwitchCase="'hint'"
4545
[@transitionMessages]="_subscriptAnimationState">
4646
<div *ngIf="hintLabel" [id]="_hintLabelId" class="mat-hint">{{hintLabel}}</div>
47-
<ng-content select="md-hint, mat-hint"></ng-content>
47+
<ng-content select="md-hint:not([align='end']), mat-hint:not([align='end'])"></ng-content>
48+
<div class="mat-input-hint-spacer"></div>
49+
<ng-content select="md-hint[align='end'], mat-hint[align='end']"></ng-content>
4850
</div>
4951
</div>
5052
</div>

src/lib/input/input-container.scss

+4-29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
$mat-input-floating-placeholder-scale-factor: 0.75 !default;
77
$mat-input-wrapper-spacing: 1em !default;
8+
$mat-input-hint-min-space: 10px !default;
89

910
// Gradient for showing the dashed line when the input is disabled.
1011
$mat-input-underline-disabled-background-image:
@@ -236,37 +237,11 @@ $mat-input-underline-disabled-background-image:
236237

237238
// Clears the floats on the hints. This is necessary for the hint animation to work.
238239
.mat-input-hint-wrapper {
239-
&::before,
240-
&::after {
241-
content: ' ';
242-
display: table;
243-
}
244-
245-
&::after {
246-
clear: both;
247-
}
240+
display: flex;
248241
}
249242

250-
// The hint is shown below the underline. There can be
251-
// more than one; one at the start and one at the end.
252-
.mat-hint {
253-
display: block;
254-
float: left;
255-
256-
// We use floats here, as opposed to flexbox, in order to make it
257-
// easier to reverse their location in rtl and to ensure that they're
258-
// aligned properly in some cases (e.g. when there is only an `end` hint).
259-
&.mat-right {
260-
float: right;
261-
}
262-
263-
[dir='rtl'] & {
264-
float: right;
265-
266-
&.mat-right {
267-
float: left;
268-
}
269-
}
243+
.mat-input-hint-spacer {
244+
flex: 1 0 $mat-input-hint-min-space;
270245
}
271246

272247
// Single error message displayed beneath the input.

0 commit comments

Comments
 (0)