Skip to content

Commit

Permalink
Make button animation duration configurable; Switch off button animat…
Browse files Browse the repository at this point in the history
…ion in snapshot test
  • Loading branch information
darrenburns committed Oct 16, 2023
1 parent 2df0584 commit 5b0d78e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 74 deletions.
15 changes: 8 additions & 7 deletions src/textual/widgets/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ 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)"""

label: reactive[TextType] = reactive[TextType]("")
"""The text label that appears within the button."""

variant = reactive("default")
"""The variant name for the button."""

active_effect_duration = 0.3
"""Amount of time in seconds the button 'press' animation lasts."""

class Pressed(Message):
"""Event sent when a `Button` is pressed.
Expand Down Expand Up @@ -252,10 +252,11 @@ def press(self) -> Self:

def _start_active_affect(self) -> None:
"""Start a small animation to show the button was clicked."""
self.add_class("-active")
self.set_timer(
self.ACTIVE_EFFECT_DURATION, partial(self.remove_class, "-active")
)
if self.active_effect_duration > 0:
self.add_class("-active")
self.set_timer(
self.active_effect_duration, partial(self.remove_class, "-active")
)

def action_press(self) -> None:
"""Activate a press of the button."""
Expand Down
Loading

0 comments on commit 5b0d78e

Please sign in to comment.