Skip to content

Commit 0a9ddcb

Browse files
committed
docs(cdk): add minimal autosize textarea example
1 parent ef620d8 commit 0a9ddcb

5 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/cdk/text-field/text-field.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ The `cdkTextareaAutosize` directive can be applied to any `<textarea>` to make i
77
resize to fit its content. The minimum and maximum number of rows to expand to can be set via the
88
`cdkAutosizeMinRows` and `cdkAutosizeMaxRows` properties respectively.
99

10+
For a textarea that only needs to resize as its content changes, no programmatic resize logic is
11+
required.
12+
13+
<!-- example(text-field-autosize-textarea-basic) -->
14+
1015
The resize logic can be triggered programmatically by calling `resizeToFitContent`. This method
1116
takes an optional boolean parameter `force` that defaults to `false`. Passing true will force the
1217
`<textarea>` to resize even if its text content has not changed, this can be useful if the styles
13-
affecting the `<textarea>` have changed.
18+
affecting the `<textarea>` have changed. For example, the following demo changes the textarea's
19+
font size and then triggers a resize.
1420

1521
<!-- example(text-field-autosize-textarea) -->
1622

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export {TextFieldAutofillDirectiveExample} from './text-field-autofill-directive/text-field-autofill-directive-example';
22
export {TextFieldAutofillMonitorExample} from './text-field-autofill-monitor/text-field-autofill-monitor-example';
3+
export {TextFieldAutosizeTextareaBasicExample} from './text-field-autosize-textarea-basic/text-field-autosize-textarea-basic-example';
34
export {TextFieldAutosizeTextareaExample} from './text-field-autosize-textarea/text-field-autosize-textarea-example';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.demo-field {
2+
margin-bottom: 16px;
3+
}
4+
5+
.demo-label {
6+
display: block;
7+
margin-bottom: 8px;
8+
}
9+
10+
.demo-textarea {
11+
box-sizing: border-box;
12+
width: 100%;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="demo-field">
2+
<label class="demo-label" for="autosize-basic">Autosize textarea</label>
3+
<textarea class="demo-textarea" id="autosize-basic" cdkTextareaAutosize></textarea>
4+
</div>
5+
6+
<div class="demo-field">
7+
<label class="demo-label" for="autosize-min-max">Autosize textarea with minimum and maximum rows</label>
8+
<textarea
9+
class="demo-textarea"
10+
id="autosize-min-max"
11+
cdkTextareaAutosize
12+
cdkAutosizeMinRows="2"
13+
cdkAutosizeMaxRows="5"></textarea>
14+
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {TextFieldModule} from '@angular/cdk/text-field';
2+
import {Component} from '@angular/core';
3+
4+
/** @title Basic auto-resizing textarea */
5+
@Component({
6+
selector: 'text-field-autosize-textarea-basic-example',
7+
templateUrl: './text-field-autosize-textarea-basic-example.html',
8+
styleUrl: './text-field-autosize-textarea-basic-example.css',
9+
imports: [TextFieldModule],
10+
})
11+
export class TextFieldAutosizeTextareaBasicExample {}

0 commit comments

Comments
 (0)