Skip to content

Commit 7df81d5

Browse files
committed
fix(material-experimental/mdc-input): add autosize directive
Adds an equivalent to `MatTextareaAutosize` in the `mdc-input` package for backwards compatibility.
1 parent bb2bb9c commit 7df81d5

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

scripts/check-mdc-exports-config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ export const config = {
2424
'_MatDialogContainerBase',
2525
'_closeDialogVia',
2626
],
27-
'mdc-input': [
28-
// TODO: an MDC version of this directive has to be implemented.
29-
'MatTextareaAutosize'
30-
],
3127
'mdc-menu': [
3228
// Private base class that is only exported for MDC.
3329
'_MatMenuBase'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {MatTextareaAutosize as BaseTextareaAutosize} from '@angular/material/input';
10+
import {Directive} from '@angular/core';
11+
12+
/**
13+
* Directive to automatically resize a textarea to fit its content.
14+
* @deprecated Use `cdkTextareaAutosize` from `@angular/cdk/text-field` instead.
15+
* @breaking-change 8.0.0
16+
*/
17+
@Directive({
18+
selector: 'textarea[mat-autosize], textarea[matTextareaAutosize]',
19+
exportAs: 'matTextareaAutosize',
20+
inputs: ['cdkAutosizeMinRows', 'cdkAutosizeMaxRows'],
21+
host: {
22+
'class': 'cdk-textarea-autosize mat-mdc-autosize',
23+
// Textarea elements that have the directive applied should have a single row by default.
24+
// Browsers normally show two rows by default and therefore this limits the minRows binding.
25+
'rows': '1',
26+
},
27+
})
28+
export class MatTextareaAutosize extends BaseTextareaAutosize {
29+
}

src/material-experimental/mdc-input/module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import {TextFieldModule} from '@angular/cdk/text-field';
1010
import {NgModule} from '@angular/core';
1111
import {MatCommonModule} from '@angular/material-experimental/mdc-core';
1212
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
13+
import {MatTextareaAutosize} from './autosize';
1314
import {MatInput} from './input';
1415

1516
@NgModule({
1617
imports: [MatCommonModule, MatFormFieldModule],
17-
exports: [MatInput, MatFormFieldModule, TextFieldModule, MatCommonModule],
18-
declarations: [MatInput],
18+
exports: [MatInput, MatTextareaAutosize, MatFormFieldModule, TextFieldModule, MatCommonModule],
19+
declarations: [MatInput, MatTextareaAutosize],
1920
})
2021
export class MatInputModule {}

src/material-experimental/mdc-input/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
export {MatInput} from './input';
1010
export {MatInputModule} from './module';
11-
11+
export {MatTextareaAutosize} from './autosize';
1212
export {
1313
getMatInputUnsupportedTypeError,
1414
MAT_INPUT_VALUE_ACCESSOR,

0 commit comments

Comments
 (0)