Skip to content

Commit b48178b

Browse files
committed
fix binding on button
1 parent 241d6c9 commit b48178b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Fixed bindings persistance https://github.com/Textualize/textual/issues/1613
1313
- The `Markdown` widget now auto-increments ordered lists https://github.com/Textualize/textual/issues/2002
1414
- Fixed modal bindings https://github.com/Textualize/textual/issues/2194
15-
15+
- Fix binding enter to active button https://github.com/Textualize/textual/issues/2194
1616

1717
## [0.17.1] - 2023-03-30
1818

src/textual/widgets/_button.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing_extensions import Literal, Self
88

99
from .. import events
10+
from ..binding import Binding
1011
from ..css._error_tools import friendly_list
1112
from ..message import Message
1213
from ..reactive import reactive
@@ -145,6 +146,8 @@ class Button(Static, can_focus=True):
145146
146147
"""
147148

149+
BINDINGS = [Binding("enter", "press", "Press Button", show=False)]
150+
148151
ACTIVE_EFFECT_DURATION = 0.3
149152
"""When buttons are clicked they get the `-active` class for this duration (in seconds)"""
150153

@@ -252,10 +255,9 @@ def _start_active_affect(self) -> None:
252255
self.ACTIVE_EFFECT_DURATION, partial(self.remove_class, "-active")
253256
)
254257

255-
async def _on_key(self, event: events.Key) -> None:
256-
if event.key == "enter" and not self.disabled:
257-
self._start_active_affect()
258-
self.post_message(Button.Pressed(self))
258+
def action_press(self) -> None:
259+
"""Activate a press if"""
260+
self.press()
259261

260262
@classmethod
261263
def success(

0 commit comments

Comments
 (0)