-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Menu: Overlay is blocking click and contextmenu events #9320
Comments
Any progress on this. I am having this problem on the auto-complete component as well. Have to click twice on item to get it selected. From what I can see it is due to the handler set on the document by the overlay. Its like it cancels events when the input is being blurred or something. I would suspect there to be a cancelbubble/propagation problem somewhere... |
Has anyone come across a workaround for this? |
Baffling how such a glaring issue as this hasn't been addressed yet. Hours researching this and the closest solution I've come across is using click simulation. Anyone actually have something more concrete? [UPDATE] [UPDATE 2] Stripped re-trigger of already open menu - now force closes active menu. Script adds "mat-menu-active" class to event target; fails menu open if target's "mat-menu-active" class is true, pass if false. Note: Make sure if you are using any icons or other objects inside of your menu item (like a button) that they're set with pointer-events:none in your CSS so pointer targeting is more clean. For the love of Athena, if anyone knows a better way to clean the below mess up, please feel free. I can't imagine this would be fully suitable for production code in an Angular environment, but it gets the job done. Still learning on my end. <script type="text/javascript">
function matMenuClearActive () {
var els = document.querySelectorAll('.mat-menu-active');
for (var i = 0; i < els.length; i++) {
els[i].classList.remove('mat-menu-active')
}
}
document.addEventListener("click",function(e){
var cdkBack = document.getElementsByClassName("cdk-overlay-backdrop")[0];
var posX = event.clientX, posY = event.clientY;
//if overlay is down & doesn't contain active class
//add a custom class to your menu container and check dom target on the following IF statement to match what you have
if ((e.target.parentElement.parentElement.classList.contains("CUSTOM CLASS")) && (!e.target.classList.contains("mat-menu-active")) ) {
matMenuClearActive();
e.target.classList.add("mat-menu-active");
} else {
// if overlay is up
if (cdkBack){
cdkBack.addEventListener("click", function () {
if (!document.elementFromPoint(posX, posY).classList.contains("mat-menu-active")) {
matMenuClearActive();
document.elementFromPoint(posX, posY).click(); //recycles function
} else {
matMenuClearActive();
}
}, true);
}
}
},true);
</script> |
If a backdrop isn't required in your case, I suggest you use the |
Hello everyone, any news on this issue ? Or is the only solutions the hacky simulated click ? |
@jelbourn: I've been following this issue and the PR that was just merged for some time. We're using backdrop right now to prevent multiple menus being open at the same time. Today I disabled the backdrop and added the new I will open a PR with my fix when it's ready and we'll see if my approach is good enough. |
For me the problem is that cdk-overlay-connected-position-bounding-box is preventing any clicks because it has too big dimensions. I added following styles: .cdk-overlay-connected-position-bounding-box
width: min-content !important
height: min-content !important This is a hack and it would be better the underlying problem would be fixed (Tested with "@angular/material": "14.2.5") The hack can break other components, for example I had to adjust datepicker also: .mat-datepicker-content
width: min-content !important
height: min-content !important |
This issue is very annoying and bad UX. I have been monitoring user sessions, and every use after clicking on a Angular material dropdown, has to click twice the Search button (or any other clickable element) to take effect, looks like a glitch, like an issue, like a bad click. I notice that the cdk-overlay-container covers all the screen causing this bug. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
When menu is open, any click event (including context menu events) outside of the menu and targeting clickable items, is expected to work from the first time. Menu should be closed along with the action handled by the clicked item.
What is the current behavior?
Overlay is blocking click events (context menu events). Clicking on the overlay first closes the menu and the user needs to click again to do his desired action (e.g. clicking navigation item that).
What are the steps to reproduce?
What is the use-case or motivation for changing an existing behavior?
The current functionality is a bad UX decision. Users usually expect to execute actions with one click (closing menu is counted towards the executed action). Making the user to click twice to close the menu and then proceed to the desired action is frustrating and not likely acceptable by most projects.
It also causes issues if developers want to do custom context menu with the Menu component.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
The text was updated successfully, but these errors were encountered: