ishwar singh chouhan
ishwar singh chouhan

Reputation: 123

angular material md-datepicker inside bootstrap modal

I am tring to use Angular material md-datepicker inside a Bootstrap modal but, on clicking the date the modal popup hides. How can i solve that problem?

<div class="modal fade " tabindex="-1" role="dialog">
   <div class="modal-dialog" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close forVideoStop" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Introduction video for body composition ...</h4>
         </div>
         <div class="modal-body">
            <md-datepicker ng-model="myDob" md-placeholder="Enter date" name="dateField" max-date="maxDate"></md-datepicker>
         </div>
      </div>
   </div>
</div>
<div class="modal fade " tabindex="-1" role="dialog">
   <div class="modal-dialog" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close forVideoStop" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Introduction video for body composition ...</h4>
         </div>
         <div class="modal-body">
            <md-datepicker ng-model="myDob" md-placeholder="Enter date" name="dateField" max-date="maxDate"></md-datepicker>
         </div>
      </div>
   </div>
</div>

How it is...

this is how it's appearing when i clicked on date

After disabling display: block in the modal class...

when i disabled  display: block in .modal class its coming like that.

Upvotes: 12

Views: 9224

Answers (4)

Marcos Oliveira
Marcos Oliveira

Reputation: 21

The working solution for me with "@angular/material": "^11.2.13" is to add my global css file below.

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

Upvotes: 2

Ali Altun
Ali Altun

Reputation: 407

The working solution for me with @angular/material 5.2.4 is to add my css file following part.

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

Upvotes: 3

Alex P.
Alex P.

Reputation: 1158

The accepted answer doesn't work for @angular/material 5.0.0-rc0 .

Instead add in the <your_component>.component.scss file:

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

::ng-deep (or /deep/) prefix needs to be used because of the view encapsulation. Note that deep is marked as deprecated in the documentation and using cdk-overlay-container is probably not a good practice since future material module changes might break it.

Upvotes: 18

Charlie
Charlie

Reputation: 664

I had the same problem, and found that this solution to a similar question actually solved the problem. You just need to add the following style to the HTML code of your modal window:

<style>
    .md-datepicker-calendar-pane {
        z-index: 1200;
    }
</style>

The other upvoted answer to the same question says that you can also modify the angular-material.css file and change the z-index there, but I don't recommend modifying the source files because your change may be reverted if you decide to update the library.

Upvotes: 7

Related Questions