Skip to content
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

Disabled menu items shouldn't close the dropdown when clicked #6412

Closed
BradFeng02 opened this issue Aug 12, 2021 · 3 comments · Fixed by #6818
Closed

Disabled menu items shouldn't close the dropdown when clicked #6412

BradFeng02 opened this issue Aug 12, 2021 · 3 comments · Fixed by #6818
Labels
bug enhancement help-wanted A contribution from the community would be most welcome.

Comments

@BradFeng02
Copy link

BradFeng02 commented Aug 12, 2021

Right now, if you have a MenuItem with IsEnabled="false", it's grayed out as expected. But when you click on it, the dropdown menu still closes. This doesn't match other UIs (like with Chrome's context menu or Visual Studio's menu, for example).

edit: it only happens with dropdowns from a top level menu item and not the flyouts for subitems

@maxkatz6 maxkatz6 added bug help-wanted A contribution from the community would be most welcome. labels Aug 14, 2021
@simonhaines
Copy link
Contributor

If no-one is working on this, I'd like to take this on. A good reason for a deep dive into the event system.

@maxkatz6
Copy link
Member

maxkatz6 commented Oct 28, 2021

@simonhaines nobody from core team has started this task yet, so it's free.
I believe this condition should be updated https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs#L381
Or maybe this one https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs#L456
Also worth to check how it works with keyboard focus.

@simonhaines
Copy link
Contributor

@maxkatz6 the first condition is where I am focusing effort, but there are some subtleties, as always. Currently the popup closes when disabled elements are clicked, but also separators, and clicks in the client area of the popup outside enabled menu items.

The simplest thing I have done that works is change the first condition to:

if (item.IsTopLevel && e.Source is not Border)
{
    CloseMenu(item);
}

This is a quick test to see if the pointer press event is bubbled from the Popup and not the top-level menu item (so that clicking the top-level item itself will close the pop-up), but I think this creates a coupling between the layout and the interaction logic that can easily break. I am exploring more reliable options.

simonhaines added a commit to simonhaines/Avalonia that referenced this issue Oct 29, 2021
Pointer clicks on disabled and non-interactive items in sub-menus
are bubbled up to the sub-menu's parent, causing the sub-menu popup
to be closed when it is expected to remain open. This scenario is
identified and filtered out by searching for a popup in the logical
tree between the source and the handler. Fixes AvaloniaUI#6412.
simonhaines added a commit to simonhaines/Avalonia that referenced this issue Oct 29, 2021
Pointer clicks on disabled and non-interactive items in sub-menus
are bubbled up to the sub-menu's parent, causing the sub-menu popup
to be closed when it is expected to remain open. This scenario is
identified and filtered out by searching for a popup in the logical
tree between the source and the handler. Fixes AvaloniaUI#6412.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants