-
Notifications
You must be signed in to change notification settings - Fork 6.8k
ability to manually control overlay's z-index #1432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Any updates?? That's really annoying |
I sort it out myself by using two stylessheet one |
Any news? There are some situations where somebody want his overlay to overlap even a fixed header. Think about tooltips. |
I am pretty sure the correct approach is something like |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
I'm horrified, but this might actually work. Thank you, @aksenovdev . This would be SO much better if we could actually just do this normally, though. I guess that depends on whether the community votes on it. Currently, if I have a fixed header, there's no way for me to specify that Menus will go above the header, |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
@am-awais If only it were that simple. That doesn't actually work, because Angular won't remove CSS that's been added to a page after the component that called it gets removed. So your 'popup' CSS is still there, and will get removed... never. The global CSS would be permanently overwritten once |
They have decided to just use BlockScrollStrategy to avoid this bug on the website. |
This issue is still present |
I'm using several overlays on one page and I need to programmatically "bring to front" one of them at a specific time. Currently I don't have a solution, it would be nice to be able to control the z-index of individual overlays to chose which one is supposed to be at the top. |
We need this! |
Here is a workaround: After opening the dialog pass the component instance, it has to have setDialogInFront(ref.componentInstance); Function that will set the dialog in front export function setDialogInFront(elementHost: {
elementRef: { nativeElement: HTMLElement };
}): void {
const element = elementHost.elementRef.nativeElement;
const mainOverlayWrapper = element.closest(
'.cdk-global-overlay-wrapper'
) as HTMLElement;
// the backdrop is the element before the main overlay wrapper
// could be null if the dialog config contains hasBackdrop: false
const mainOverlayBackDrop =
mainOverlayWrapper.previousElementSibling as HTMLElement | null;
// get the max z-index of the other dialogs
let maxZIndex = 0;
document
.querySelectorAll('.cdk-global-overlay-wrapper')
.forEach((wrapper) => {
const zIndex = parseInt(
window.getComputedStyle(wrapper).getPropertyValue('z-index'),
10
);
maxZIndex = Math.max(maxZIndex, zIndex);
});
// set the z-index of the main dialog to be one higher than the max
mainOverlayWrapper.style.zIndex = `${maxZIndex + 1}`;
if (mainOverlayBackDrop) {
mainOverlayBackDrop.style.zIndex = `${maxZIndex + 1}`;
}
} Example dialog component export class MyDialogComponent {
public elementRef: ElementRef<HTMLElement> = inject(ElementRef);
} |
Would you please provide with some api to control zindex of overlay? |
Any solutions now? That’s big problem. Please provide some api to control zindex. |
When you create an overlay with (overlayRef['_host'] as HTMLElement).style.zIndex = `${zIndex}`; You can set the zIndex property either programmatically or by selecting all the elements with the class name 'cdk-global-overlay-wrapper' and increasing their values as needed. For example: const DEFAULT_ZINDEX = 1000;
const zIndex = DEFAULT_ZINDEX + document.querySelectorAll('.cdk-global-overlay-wrapper').length + 1; |
This is the only thing I could get to work the way I needed.. however vscode does not like that syntax. |
Uh oh!
There was an error while loading. Please reload this page.
This would be handy for both user created overlays, as well as those used by angular components such as md-menu.
Take this for example http://plnkr.co/edit/AqjYdsScCYPlK9w44aHQ?p=preview you have a fixed element(some sort custom toolbar), inside it you have a button which triggers md-menu, it works fine, but the
md-menu-click-catcher
, which is for some reason inside the actualmd-menu
element, is actually stacked abovemd-overlay-container
, causing any attempt to click on the menu items to close the menu(which can be extremely confusing).md-overlay-container
should not have z-index at all, as it renders z-indexes ofmd-overlay-pane
uselessmd-overlay-pane
I imagine(at least for the user invoked overlay), it could work either by being able to give the overlay my own identificator(class at least), or being able to set it via
OverlayState
settings.. the former is preferable, as you can then easily switch z-indexes with media queries.The text was updated successfully, but these errors were encountered: