Skip to content

fix(material-experimental/mdc-input): add autosize directive #21105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions scripts/check-mdc-exports-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export const config = {
'_MatDialogContainerBase',
'_closeDialogVia',
],
'mdc-input': [
// TODO: an MDC version of this directive has to be implemented.
'MatTextareaAutosize'
],
'mdc-menu': [
// Private base class that is only exported for MDC.
'_MatMenuBase'
Expand Down
29 changes: 29 additions & 0 deletions src/material-experimental/mdc-input/autosize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {MatTextareaAutosize as BaseTextareaAutosize} from '@angular/material/input';
import {Directive} from '@angular/core';

/**
* Directive to automatically resize a textarea to fit its content.
* @deprecated Use `cdkTextareaAutosize` from `@angular/cdk/text-field` instead.
* @breaking-change 8.0.0
*/
@Directive({
selector: 'textarea[mat-autosize], textarea[matTextareaAutosize]',
exportAs: 'matTextareaAutosize',
inputs: ['cdkAutosizeMinRows', 'cdkAutosizeMaxRows'],
host: {
'class': 'cdk-textarea-autosize mat-mdc-autosize',
// Textarea elements that have the directive applied should have a single row by default.
// Browsers normally show two rows by default and therefore this limits the minRows binding.
'rows': '1',
},
})
export class MatTextareaAutosize extends BaseTextareaAutosize {
}
5 changes: 3 additions & 2 deletions src/material-experimental/mdc-input/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {TextFieldModule} from '@angular/cdk/text-field';
import {NgModule} from '@angular/core';
import {MatCommonModule} from '@angular/material-experimental/mdc-core';
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
import {MatTextareaAutosize} from './autosize';
import {MatInput} from './input';

@NgModule({
imports: [MatCommonModule, MatFormFieldModule],
exports: [MatInput, MatFormFieldModule, TextFieldModule, MatCommonModule],
declarations: [MatInput],
exports: [MatInput, MatTextareaAutosize, MatFormFieldModule, TextFieldModule, MatCommonModule],
declarations: [MatInput, MatTextareaAutosize],
})
export class MatInputModule {}
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-input/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export {MatInput} from './input';
export {MatInputModule} from './module';

export {MatTextareaAutosize} from './autosize';
export {
getMatInputUnsupportedTypeError,
MAT_INPUT_VALUE_ACCESSOR,
Expand Down