3

Helloo, I have a problem on my view using angular 4 and bootstrap 4. When I click on open to show calendar. It's showing behind my modal. I want to change z-index on its class but i don't have acces to the class because it's auto-generated. How can i fix the probleme? enter image description here This is my code. enter image description here Thanks in advance.

Fatim
  • 155
  • 3
  • 3
  • 13

2 Answers2

8

The issue is that bootstrap-modal sets z-index:1050

.modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    display: none;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    outline: 0;
}

The material date picker sets z-index: 1000 when the ckd-overlay-pane is created

.cdk-overlay-pane {
    position: absolute;
    pointer-events: auto;
    box-sizing: border-box;
    z-index: 1000;
    display: flex;
    max-width: 100%;
    max-height: 100%;
}

Adding this to your component style sheet should do the trick... but this will apply to all date-pickers in your entire project.

  • You will need to include a custom class identifier to make this specific to your modal date-picker if you only want to change that one.

    ::ng-deep .cdk-overlay-container mat-datepicker-content{
      z-index:2000;
    }
    

Please reference the answer on this SO question for why using ::ng-deep is ok until further notice.

What to use in place of ::ng-deep

Marshal
  • 10,499
  • 2
  • 34
  • 53
0

Adding this to your component style sheet

.cdk-overlay-container { z-index: 1200 !important; }

  • Does this answer add anything to Marshal's accepted one from 2018 or [Alex Guerreiro's 2020 comment](https://stackoverflow.com/questions/53527964/mat-datepicker-toggle-showing-behind-modal/75533692#comment112012344_53528470)? – greybeard Mar 02 '23 at 08:48