Skip to content

Commit 4e2e0a5

Browse files
committed
add comments
1 parent 3877ff6 commit 4e2e0a5

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/cdk/text-field/_text-field.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
resize: none;
2121
}
2222

23+
// This class is temporarily applied to the textarea when it is being measured. It is immediately
24+
// removed when measuring is complete. We use `!important` rules here to make sure user-specified
25+
// rules do not interfere with the measurement.
2326
textarea.cdk-textarea-autosize-measuring {
2427
height: auto !important;
2528
overflow: hidden !important;
29+
// Having 2px top and bottom padding seems to fix a bug where Chrome gets an incorrect
30+
// measurement. We just have to account for it later and subtract it off the final result.
2631
padding: 2px 0 !important;
2732
box-sizing: content-box !important;
2833
}

src/cdk/text-field/autosize.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
190190
textarea.classList.add('cdk-textarea-autosize-measuring');
191191
textarea.placeholder = '';
192192

193-
// Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
194-
// We subtract 4 from the scrollHeight because of the 2px top and bottom padding. Having the
195-
// extra 2px on either side seems to fix inaccurate measurements in Chrome.
193+
// The cdk-textarea-autosize-measuring class includes a 2px padding to workaround an issue with
194+
// Chrome, so we account for that extra space here by subtracting 4 (2px top + 2px bottom).
196195
textarea.style.height = `${textarea.scrollHeight - 4}px`;
197196

198197
textarea.classList.remove('cdk-textarea-autosize-measuring');

src/lib/input/input.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ textarea.mat-input-element {
9494
}
9595

9696
textarea.mat-input-element {
97+
// The 2px padding prevents scrollbars from appearing on Chrome even when they aren't needed.
98+
// We also add a negative margin to negate the effect of the padding on the layout.
9799
padding: 2px 0;
98100
margin: -2px 0;
99101
}

0 commit comments

Comments
 (0)