This is a prototype of an alternate version of MatInput
built on top of
MDC Web. This component is
experimental and should not be used in production.
Assuming your application is already up and running using Angular Material, you can add this component by following these steps:
-
Install
@angular/material-experimental
and MDC Web:npm i material-components-web @angular/material-experimental
-
In your
angular.json
, make surenode_modules/
is listed as a Sass include path. This is needed for the Sass compiler to be able to find the MDC Web Sass files.... "styles": [ "src/styles.scss" ], "stylePreprocessorOptions": { "includePaths": [ "node_modules/" ] }, ...
-
Import the experimental
MatInputModule
and add it to the module that declares your component:import {MatInputModule} from '@angular/material-experimental/mdc-input'; @NgModule({ declarations: [MyComponent], imports: [MatInputModule], }) export class MyModule {}
-
Use
MatInput
in your component's template in combination with the MDC-basedmat-form-field
. Similarly to the input module from@angular/material
, the MDC-based input module exposes the form-field module.<mat-form-field> <mat-label>Full name</mat-label> <input matInput> </mat-form-field>
-
Ensure color and typography styles for
@angular/material-experimental
are set up. The input itself does not provide any styles. If an input is used inside of the MDC-basedmat-mdc-form-field
, either use a custom theme with themat-form-field-theme
mixin, or use a prebuilt theme from@angular/material-experimental/mdc-theming/prebuilt
.
The API of input matches the one from @angular/material/input
. Simply replace imports to
@angular/material/input
with imports to @angular/material-experimental/mdc-input
.