Skip to content

Commit 502a2c2

Browse files
fix(components/forms): constrain input box textarea height to prevent text overlapping with label (#796)
1 parent 87094cd commit 502a2c2

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

libs/components/forms/src/lib/modules/input-box/input-box.component.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@
8787
</ng-template>
8888

8989
<ng-template #inputTemplate>
90-
<ng-content select=".sky-form-control"></ng-content>
90+
<ng-content select=".sky-form-control:not(textarea)"></ng-content>
9191
<ng-container *ngIf="hostInputTemplate">
9292
<ng-container *ngTemplateOutlet="hostInputTemplate"></ng-container
9393
></ng-container>
94+
<!--
95+
Text inside a textarea displays over the textarea's padding instead of under it,
96+
causing text to overlap with the input box's label element when scrolled. Use a
97+
wrapping element around textarea with its own padding and negative margin instead.
98+
-->
99+
<div class="sky-input-box-textarea-wrapper">
100+
<ng-content select="textarea.sky-form-control"></ng-content>
101+
</div>
94102
</ng-template>
95103

96104
<ng-template #buttonsLeftTemplate>

libs/components/forms/src/lib/modules/input-box/input-box.component.scss

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ sky-input-box {
9999
width: initial;
100100
}
101101
}
102+
103+
.sky-input-box-textarea-wrapper {
104+
/* Setting line-height to 0 eliminates extra whitespace under the textarea */
105+
line-height: 0;
106+
width: 100%;
107+
108+
&:empty {
109+
display: none;
110+
}
111+
}
102112
}
103113

104114
.sky-theme-modern {
@@ -278,6 +288,17 @@ sky-input-box {
278288
}
279289
}
280290

291+
/*
292+
Text inside a textarea displays over the textarea's padding instead of under it,
293+
causing text to overlap with the input box's label element when scrolled. Use a
294+
wrapping element around textarea with its own padding and negative margin instead.
295+
*/
296+
.sky-form-control,
297+
.sky-input-box-textarea-wrapper {
298+
margin-top: -23px;
299+
padding-top: 26px;
300+
}
301+
281302
.sky-form-control {
282303
background-color: transparent;
283304
border: none;
@@ -291,8 +312,9 @@ sky-input-box {
291312
*/
292313
height: auto;
293314
line-height: 18px;
294-
margin-top: -23px;
295-
padding: 26px 15px 10px 15px;
315+
padding-right: 15px;
316+
padding-bottom: 10px;
317+
padding-left: 15px;
296318
position: relative;
297319

298320
&:first-line {
@@ -362,6 +384,8 @@ sky-input-box {
362384
}
363385

364386
textarea.sky-form-control {
387+
margin-top: 0;
388+
padding-top: 0;
365389
resize: vertical;
366390
}
367391
}

0 commit comments

Comments
 (0)