We have to show a form inside mat-expansion-panel. There are multiple fields in the form, for few of them I am using mat-select and for another few I am using mat-input.
In expansion panel, matInput is working fine but mat-select is not showing the options for selecting a possible value.
Though mat-select is working fine when showed normally.
<mat-expansion-panel>
<mat-expansion-panel-header>
Heading 1
</mat-expansion-panel-header>
<mat-form-field>
<mat-select placeholder="Select">
<mat-option value="1">option 1</mat-option>
<mat-option value="2">option 2</mat-option>
<mat-option value="3">option 3</mat-option>
<mat-option value="4">option 4</mat-option>
</mat-select>
</mat-form-field>
</mat-expansion-panel>
Any help is appreciated.
By default, the expansion panel content will be initialized even when the panel is closed. To instead defer initialization until the panel is open, the content should be provided as an ng-template: <mat-expansion-panel> <mat-expansion-panel-header>
Create Select using <mat-select> To add elements to select option, we need to use <mat-option> element. To bind value with <mat-option> , we need to use value property of it. The <mat-select> has also value property to bind selected value to keep it selected. We need to use <mat-select> inside <mat-form-field> element.
Expansion panels can be disabled using the disabled attribute. A disabled expansion panel can't be toggled by the user, but can still be manipulated programmatically.
I solved it by adding following styles
body div.cdk-overlay-container {
z-index: 1000000;
}
By debugging, I got to know that another panel with higher z-index was overriding the mat-select options. I provided the increase z-index value to cdk-overlay-container and it worked.
Thanks for your support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With