question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cdk(feature): Provide custom overlay container

See original GitHub issue

Bug, 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
insansicommented, Oct 5, 2017

I’m having the exact same issue. cdk-overlay-container is causing the options in md-select to appear outside the body.

1reaction
jgeiger-crcommented, Mar 5, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found