Reputation: 193
I'm new to Angular Material and I'm building a datepicker. I need to move the icon from outside of the input field to inside. I tried importing some Material themes and I haven't found one that has this style, does anyone know how to do this? This is my html:
<input matInput formControlName="startDate" [matDatepicker]="basicDatepicker" (click)="basicDatepicker.open()" >
<mat-datepicker-toggle matSuffix [for]="basicDatepicker"></mat-datepicker-toggle>
<mat-datepicker #basicDatepicker></mat-datepicker>
Upvotes: 1
Views: 4609
Reputation: 193
Thank you guys! I used this:
<mat-form-field appearance="outline">
And customized the classes as suggested using ::ng-deep
Upvotes: 0
Reputation: 68
You can use css to do this set the icon to be hidden, and place an icon of your own source outside the calendar.
inspect the icon class and set his visibility with something like this
::ng-deep .targetClass {
visibility: hidden;
}
You need to use ng-deep to get classes deep-in angular components
I suggest wrapping the calendar with another class, so your CSS only affects the target calendar
Like this:
.wrapperClass ::ng-deep .targetClass {
visibility: hidden;
}
Upvotes: 1
Reputation: 151
To make it look like the actual material one your code should look like this:
<mat-form-field appearance="fill">
<mat-label>Choose a date</mat-label>
<input matInput [matDatepicker]="picker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
You can see more details and other kind of implementations on the docs: https://material.angular.io/components/datepicker/overview
Upvotes: 2