Skip to content

Commit e0fe635

Browse files
crisbetotinayuangao
authored andcommitted
fix(input): horizontal overflow in IE and Edge (#2784)
* fix(input): horizontal overflow in IE and Edge Currently input labels are set to 133% width and are scaled down to fit into their container. This works fine in most browsers, however it causes horizontal overflows on IE and Edge, because they don't consider the `transform` when determining whether an element overflows. This change fixes it by hiding all of the overflowing content. * refactor: use alternative approach * chore: re-add the fix after faulty merge
1 parent a7a3967 commit e0fe635

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/lib/input/input-container.html

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
<div class="mat-input-infix" [class.mat-end]="align == 'end'">
99
<ng-content selector="input, textarea"></ng-content>
1010

11-
<label class="mat-input-placeholder"
12-
[attr.for]="_mdInputChild.id"
13-
[class.mat-empty]="_mdInputChild.empty && !_shouldAlwaysFloat"
14-
[class.mat-focused]="_mdInputChild.focused"
15-
[class.mat-float]="_canPlaceholderFloat"
16-
[class.mat-accent]="dividerColor == 'accent'"
17-
[class.mat-warn]="dividerColor == 'warn'"
18-
*ngIf="_hasPlaceholder()">
19-
<ng-content select="md-placeholder, mat-placeholder"></ng-content>
20-
{{_mdInputChild.placeholder}}
21-
<span class="mat-placeholder-required" *ngIf="_mdInputChild.required">*</span>
22-
</label>
11+
<span class="mat-input-placeholder-wrapper">
12+
<label class="mat-input-placeholder"
13+
[attr.for]="_mdInputChild.id"
14+
[class.mat-empty]="_mdInputChild.empty && !_shouldAlwaysFloat"
15+
[class.mat-focused]="_mdInputChild.focused"
16+
[class.mat-float]="_canPlaceholderFloat"
17+
[class.mat-accent]="dividerColor == 'accent'"
18+
[class.mat-warn]="dividerColor == 'warn'"
19+
*ngIf="_hasPlaceholder()">
20+
<ng-content select="md-placeholder, mat-placeholder"></ng-content>
21+
{{_mdInputChild.placeholder}}
22+
<span class="mat-placeholder-required" *ngIf="_mdInputChild.required">*</span>
23+
</label>
24+
</span>
2325
</div>
2426

2527
<div class="mat-input-suffix">

src/lib/input/input-container.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ $mat-input-underline-disabled-background-image:
128128
font-size: 100%;
129129
pointer-events: none; // We shouldn't catch mouse events (let them through).
130130
z-index: 1;
131+
padding-top: 1em;
131132

132133
// Put ellipsis text overflow.
133134
width: 100%;
@@ -159,6 +160,24 @@ $mat-input-underline-disabled-background-image:
159160
}
160161
}
161162

163+
// Used to hide the placeholder overflow on IE, since IE doesn't take transform into account when
164+
// determining overflow.
165+
.mat-input-placeholder-wrapper {
166+
position: absolute;
167+
left: 0;
168+
top: -1em;
169+
width: 100%;
170+
padding-top: 1em;
171+
overflow: hidden;
172+
pointer-events: none; // We shouldn't catch mouse events (let them through).
173+
174+
// Keeps the element height since the placeholder text is `position: absolute`.
175+
&::after {
176+
content: '\\00a0';
177+
}
178+
}
179+
180+
162181
// The underline is what's shown under the input, its prefix and its suffix.
163182
// The ripple is the blue animation coming on top of it.
164183
.mat-input-underline {

0 commit comments

Comments
 (0)