For people who have cdk-overlay (cdk-panel) with md-select.
Suppose you are using Angular 2, Typescript, Pug, and Material Design Lite (MDL) in a production environment.
The function that md-select styles work when clicked.
Javascript (TypeScript) in component
@Component({ selector: .., templateUrl: .., styleUrl: .., // For re-calculating on resize host: { '(window:resize)': 'onResize()' } }) export class MyComponent { //Function to style md-select BEGIN public styleSelectDropdown(event) { var bodyRect = document.body.getBoundingClientRect(); let dropdown = document.getElementsByClassName("cdk-overlay-pane") as HTMLCollectionOf<HTMLElement>; if (dropdown.length > 0) { for(var i = 0; i < dropdown.length; i++) { dropdown[i].style.top = "auto"; dropdown[i].style.bottom = "auto"; dropdown[i].style.left = "auto"; } for(var i = 0; i < dropdown.length; i++) { if (dropdown[i].innerHTML != "") { var getDropdownId = dropdown[i].id; document.getElementById(getDropdownId).classList.add('pane-styleSelectDropdown'); } } } let target = event.currentTarget; let selectLine = target.getElementsByClassName("mat-select-underline") as HTMLCollectionOf<HTMLElement>; if (selectLine.length > 0) { var selectLineRect = selectLine[0].getBoundingClientRect(); } let targetPanel = target.getElementsByClassName("mat-select-content") as HTMLCollectionOf<HTMLElement>; if (targetPanel.length > 0) { var selectLineRect = selectLine[0].getBoundingClientRect(); } if (dropdown.length > 0) { for(var i = 0; i < dropdown.length; i++) { dropdown[i].style.top = selectLineRect.top + "px"; dropdown[i].style.bottom = 0 + "px"; dropdown[i].style.left = selectLineRect.left + "px"; } } var windowHeight = window.outerHeight; if (targetPanel.length > 0) { targetPanel[0].style.maxHeight = window.outerHeight - selectLineRect.top + "px"; } } public onResize() { this.styleSelectDropdown(event); } //Function to style md-select END }
HTML (Pug)
.form-container div.styleSelectDropdown((click)="styleSelectDropdown($event)") md-select.form-group(md-container-class="my-container", id = '...', md-option(....)
CSS that overrides the construction of Lite (MDL) css materials
.pane-styleSelectDropdown .mat-select-panel { border: none; min-width: initial !important; box-shadow: none !important; border-top: 2px #3f51b5 solid !important; position: relative; overflow: visible !important; } .pane-styleSelectDropdown .mat-select-panel::before { content: ""; position: absolute; top: -17px; right: 0; display: block; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid #3f51b5; margin: 0 4px; z-index: 1000; } .pane-styleSelectDropdown .mat-select-content { border: 1px solid #e0e0e0; box-shadow: 0 2px 1px #e0e0e0; position: relative; } @media screen and (max-height: 568px) { .pane-styleSelectDropdown .mat-select-content { overflow-y: scroll; } } .pane-styleSelectDropdown.cdk-overlay-pane { top: 0; bottom: 0; left: 0; overflow: hidden; padding-bottom: 5px; z-index: 10000; } .pane-styleSelectDropdown .mat-select-panel .mat-option.mat-selected:not(.mat-option-multiple), .pane-styleSelectDropdown .mat-option:focus:not(.mat-option-disabled), .pane-styleSelectDropdown .mat-option:hover:not(.mat-option-disabled) { background: #fff !important; } .pane-styleSelectDropdown .mat-option { line-height: 36px; height: 36px; font-size: 14px; }
Olga
source share