|
1 |
| -This is a placeholder for the MDC-based implementation of input. |
| 1 | +This is a prototype of an alternate version of `MatInput` built on top of |
| 2 | +[MDC Web](https://github.com/material-components/material-components-web). This component is |
| 3 | +experimental and should not be used in production. |
| 4 | + |
| 5 | +## How to use |
| 6 | +Assuming your application is already up and running using Angular Material, you can add this |
| 7 | +component by following these steps: |
| 8 | + |
| 9 | +1. Install `@angular/material-experimental` and MDC Web: |
| 10 | + |
| 11 | + ```bash |
| 12 | + npm i material-components-web @angular/material-experimental |
| 13 | + ``` |
| 14 | + |
| 15 | +2. In your `angular.json`, make sure `node_modules/` is listed as a Sass include path. This is |
| 16 | + needed for the Sass compiler to be able to find the MDC Web Sass files. |
| 17 | + |
| 18 | + ```json |
| 19 | + ... |
| 20 | + "styles": [ |
| 21 | + "src/styles.scss" |
| 22 | + ], |
| 23 | + "stylePreprocessorOptions": { |
| 24 | + "includePaths": [ |
| 25 | + "node_modules/" |
| 26 | + ] |
| 27 | + }, |
| 28 | + ... |
| 29 | + ``` |
| 30 | + |
| 31 | +3. Import the experimental `MatInputModule` and add it to the module that declares your |
| 32 | + component: |
| 33 | + |
| 34 | + ```ts |
| 35 | + import {MatInputModule} from '@angular/material-experimental/mdc-input'; |
| 36 | + |
| 37 | + @NgModule({ |
| 38 | + declarations: [MyComponent], |
| 39 | + imports: [MatInputModule], |
| 40 | + }) |
| 41 | + export class MyModule {} |
| 42 | + ``` |
| 43 | + |
| 44 | +4. Use `MatInput` in your component's template in combination with the MDC-based `mat-form-field`. |
| 45 | + Similarly to the input module from `@angular/material`, the MDC-based input module exposes |
| 46 | + the form-field module. |
| 47 | + |
| 48 | + ```html |
| 49 | + <mat-form-field> |
| 50 | + <mat-label>Full name</mat-label> |
| 51 | + <input matInput> |
| 52 | + </mat-form-field> |
| 53 | + ``` |
| 54 | + |
| 55 | +5. Ensure color and typography styles for `@angular/material-experimental` are set up. The input |
| 56 | + itself does not provide any styles. If an input is used inside of the MDC-based |
| 57 | + `mat-form-field`, either use a custom theme with the `mat-form-field-theme-mdc` mixin, or use |
| 58 | + a prebuilt theme from `@angular/material-experimental/mdc-theming/prebuilt`. |
| 59 | + |
| 60 | +## API differences |
| 61 | + |
| 62 | +The API of input matches the one from `@angular/material/input`. Simply replace imports to |
| 63 | +`@angular/material/input` with imports to `@angular/material-experimental/mdc-input`. |
0 commit comments