Fix mouse wheel & show description when hovering over grayed menu items

This commit is contained in:
Isaiah Odhner 2023-04-24 00:56:51 -04:00
parent c12036880e
commit 2cdb728d64
2 changed files with 11 additions and 1 deletions

View File

@ -71,6 +71,10 @@ class Menu(Container):
"""Called when a button is clicked or activated with the keyboard."""
if isinstance(event.button, MenuItem):
if event.button.has_class("grayed"):
# TODO: use disabled property once Textual fixes mouse wheel events on disabled buttons
# and we have a way to listen for the mouse Enter event on disabled buttons
return
if event.button.action:
event.button.action()
root_menu = self
@ -208,7 +212,10 @@ class MenuItem(Button):
"""Initialize a menu item."""
super().__init__(markup_hotkey(name), **kwargs)
self.hotkey: str|None = get_hotkey(name)
self.disabled = grayed
# self.disabled = grayed # This breaks scroll wheel over the menu item, as of Textual 0.20.1
if grayed:
self.add_class("grayed")
self.can_focus = False
self.action = action
self.submenu = submenu
self.description = description

View File

@ -119,6 +119,9 @@ MenuItem {
width: auto;
height: auto;
}
MenuItem.grayed {
color: #777;
}
Separator {
width: 100%;
height: 1;