I'm trying to create a toolbar using Material's mat-toolbar
with an input and select inside of it. For both, I am using Material's provided components (mat-input
and mat-select
respectively) inside of mat-form-field
s as advised. My code looks like this:
<mat-toolbar>
<mat-form-field appearance="outline">
<mat-icon matPrefix>search</mat-icon>
<input type="search" matInput placeholder="Search" />
</mat-form-field>
<mat-form-field appearance="outline">
<mat-select [(value)]="omitted">
<mat-option *ngFor="let omitted of omitted" [value]="omitted.slug">
{{ omitted.name }}
</mat-option>
</mat-select>
</mat-form-field>
</mat-toolbar>
At the moment, the input and select are too tall to completely fit in the toolbar. I am trying to style them to make them fit (by reducing height
, padding
, margin
, etc.). However, Angular adds elements between mat-form-field
and the contained elements. I am unable to style those elements from the component's Sass because of view encapsulation. So, even if I style everything immediately present in my template, the generated elements have heights, margins, and paddings that force the observed element to be outside of the toolbar.
I don't want to include a global style for those components because I don't want other mat-form-field
s to get affected.
Turning off view encapsulation would essentially be the same thing as using global styling.
::ng-deep
is deprecated so I can't use that.
I could style my own input
and select
from scratch, but then I lose out on the prebuilt styling that Material provides. Is there any way that I can style these Material components to fit in my toolbar?