fix binding on button

This commit is contained in:
Will McGugan
2023-04-01 18:34:51 +01:00
parent 241d6c989d
commit b48178b80d
2 changed files with 7 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed bindings persistance https://github.com/Textualize/textual/issues/1613
- The `Markdown` widget now auto-increments ordered lists https://github.com/Textualize/textual/issues/2002
- Fixed modal bindings https://github.com/Textualize/textual/issues/2194
- Fix binding enter to active button https://github.com/Textualize/textual/issues/2194
## [0.17.1] - 2023-03-30

View File

@@ -7,6 +7,7 @@ from rich.text import Text, TextType
from typing_extensions import Literal, Self
from .. import events
from ..binding import Binding
from ..css._error_tools import friendly_list
from ..message import Message
from ..reactive import reactive
@@ -145,6 +146,8 @@ class Button(Static, can_focus=True):
"""
BINDINGS = [Binding("enter", "press", "Press Button", show=False)]
ACTIVE_EFFECT_DURATION = 0.3
"""When buttons are clicked they get the `-active` class for this duration (in seconds)"""
@@ -252,10 +255,9 @@ class Button(Static, can_focus=True):
self.ACTIVE_EFFECT_DURATION, partial(self.remove_class, "-active")
)
async def _on_key(self, event: events.Key) -> None:
if event.key == "enter" and not self.disabled:
self._start_active_affect()
self.post_message(Button.Pressed(self))
def action_press(self) -> None:
"""Activate a press if"""
self.press()
@classmethod
def success(