cdk(feature): Provide custom overlay container
See original GitHub issueBug, feature request, or proposal:
[x] Feature request
What is the expected behavior?
In certain scenarios the overlay container has to be positioned somewhere else than as last element of document.body. The developer should be able to provide a NativeElement (HTMLElement) to CDK referencing a container to be used as overlay container.
What is the current behavior?
Overlay container is appended as last element to document.body
What is the use-case or motivation for changing an existing behavior?
In my case I have a themeing component, inside which all the material styling is applied but the overlay isn’t matched as it is positioned outside.
Only applying the class to the container isn’t enough as it has to be a child of <my-theme>
.
<my-app>
<my-theme class="myAngularMaterialTheme">
<!-- all components here get styled correctly //-->
</my-theme>
</my-app>
<div class="cdk-overlay-container"></div>
Currently I’m hacking it by changing it’s position inside MyThemeComponent:
@Component({})
export class MyThemeComponent {
constructor(elementReference: ElementRef, overlayContainer: OverlayContainer) {
if(overlayContainer.getContainerElement()) {
setTimeout(() => elementReference.nativeElement.appendChild(overlayContainer.getContainerElement()), 0);
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Overlay | Angular Material
The overlay package provides a way to open floating panels on the screen. ... The CDK overlays depend on a small set of...
Read more >Custom Overlays with Angular's CDK - Thoughtram Blog
In this post, we'll use the CDK to build a custom overlay that looks and feels much like the Google Drive file preview...
Read more >How do I create a custom overlay container for angular material
Was missing Injectable : @Injectable({providedIn: 'root'}) export class CdkOverlayContainer extends OverlayContainer { ... Also @angular/cdk ...
Read more >How to display an overlay with Angular? | by Alain Chautard
In this post, we will explore how to use the Angular CDK (Component Development Kit) to create an overlay that renders some content...
Read more >A loader for your components with Angular CDK Overlay
To do so, we will use the Angular CDK Overlay feature. Angular Material. Overlay CDK Feature ... A customized loader thanks to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the exact same issue. cdk-overlay-container is causing the options in md-select to appear outside the body.
@actra-gschuster any chance you could provide a bit more detail? I’m struggling to fully implement your approach yet it seems exactly what I need. Anyway thanks a lot for your idea.