18

i Used the ngx-bootstrap Modal. But i faced problem when i used the mat-select inside of it . The mat-select Options display behind the Modal . i already these solutions here solution and also this one

here is my code

<ng-template style="border: 0px ;z-index: 100" #editTemplate>
  <mat-form-field>
                <mat-select multiple placeholder="Multiple Cities" [(ngModel)]="currentCity" name="Paris" ariaLabel="cities[0]">
                  <mat-option *ngFor="let city of cities" [value]="city.value">
                    {{ city.viewValue }}
                  </mat-option>
                </mat-select>
              </mat-form-field>
<ng-template>
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Hassan Amjad
  • 399
  • 1
  • 6
  • 20

9 Answers9

23

It's because of conflicting z-indexes.

Quick fix

Modify the template css/scss where the modal and mat-select are placed

  .cdk-global-overlay-wrapper, .cdk-overlay-container {
     z-index: 99999 !important;
  }
Debojyoti
  • 4,503
  • 3
  • 19
  • 27
19

The issue occurs due to conflicting z-indexes. Add the below style in your global CSS file(styles.css file)

.cdk-global-overlay-wrapper, .cdk-overlay-container { z-index: 9999!important; } 

And make sure you refer this styles in your angular.json file

"styles": [ "src/styles.css", "src/......." ]
Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
Shijitha
  • 191
  • 1
  • 4
8

I found the above answers didn't seem to work but the code below did

.cdk-overlay-connected-position-bounding-box {
  z-index: 99999 !important;
}

This needs to go in a global (s)css file to work

This shows any mat-select options on top of any open modals :)

Luke Bellamy
  • 99
  • 1
  • 3
3

Not recommeding the z-index: 99999 !important; AT ALL. It's a very exteme soultion that should be used only as a last resort.

In my case it was that the modal was opened in a non-standard way. If you open it using MatDialog service you shouldn't find any issues. If there is then your code is what introduced them, try not to hack your way into a fix.

Zahema
  • 1,345
  • 2
  • 19
  • 35
  • 1
    your absolutely right! I have tried all the solution above among with answers from different questions, and your answer is the one answer that worked! @Zahema – Hila Grossbard Dec 23 '20 at 09:59
3

You can add this link of code in SCSS file .cdk-overlay-container { z-index: 1127; } class cdk-overlay-container (angular materiel class) which is the default behavior. To override this just decrease or increase the cdk-overlay-container z-index to 1000 so that it go behind or front the combo and all things ok to me

2

2022, I got it working just adding this:

::ng-deep .cdk-overlay-container {
    z-index: 9999;
}

Very important the ::ng-deep selector before the class (not /deep/ which is deprecated now) otherwise it wasn't able to find the class because it's not in the DOM yet and not in your component's HTML. If you want to apply this CSS change to that component and its child, add also :host selector before the ::ng-deep. More info about host and ng-deep here.

If still doesn't work try adding "!important" after the z-index value or try increasing the z-index (adding more 9) if maybe you have elements already with that z-index.

Another path to contemplate might be using material own modals- material dialog. Won't have z-index problems with that, but that wasn't the question here ;)

phoenix
  • 41
  • 1
0

I solved the problem adding Angular animations in app.module.ts:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
metodribic
  • 1,561
  • 17
  • 27
0

2022 I solved this problem just by adding in my component style file

::ng-deep .cdk-overlay-container { z-index: 9999;}

0

if you are using module wise like admin user then add this in your component css file it will not work by adding in style.css i am using NgbModal

::ng-deep .cdk-overlay-container {
    z-index: 9999;
}
Shahid
  • 159
  • 5
  • 14