File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
66and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
77
8-
98## Unreleased
109
1110### Changed
@@ -29,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2928- Added new demo ` python -m textual ` , not * quite* finished but better than the old one https://github.com/Textualize/textual/pull/5174
3029- Added ` Screen.can_view_partial ` and ` Widget.can_view_partial ` https://github.com/Textualize/textual/pull/5174
3130- Added ` App.is_web ` property to indicate if the app is running via a web browser https://github.com/Textualize/textual/pull/5128
31+ - ` Enter ` and ` Leave ` events can now be used with the ` on ` decorator https://github.com/Textualize/textual/pull/5159
3232
3333### Fixed
3434
Original file line number Diff line number Diff line change @@ -572,6 +572,11 @@ def __init__(self, node: DOMNode) -> None:
572572 """The node directly under the mouse."""
573573 super ().__init__ ()
574574
575+ @property
576+ def control (self ) -> DOMNode :
577+ """Alias for the `node` under the mouse."""
578+ return self .node
579+
575580
576581class Leave (Event , bubble = True , verbose = True ):
577582 """Sent when the mouse is moved away from a widget, or if a widget is
@@ -592,6 +597,11 @@ def __init__(self, node: DOMNode) -> None:
592597 """The node that was previously directly under the mouse."""
593598 super ().__init__ ()
594599
600+ @property
601+ def control (self ) -> DOMNode :
602+ """Alias for the `node` that was previously under the mouse."""
603+ return self .node
604+
595605
596606class Focus (Event , bubble = False ):
597607 """Sent when a widget is focussed.
Original file line number Diff line number Diff line change 77from textual import on
88from textual ._on import OnDecoratorError
99from textual .app import App , ComposeResult
10+ from textual .events import Enter , Leave
1011from textual .message import Message
1112from textual .widget import Widget
1213from textual .widgets import Button , TabbedContent , TabPane
@@ -352,3 +353,28 @@ def on_mount(self) -> None:
352353 pass
353354
354355 assert posted == ["parent" , "child" , "parent" ]
356+
357+
358+ async def test_on_with_enter_and_leave_events ():
359+ class EnterLeaveApp (App ):
360+ messages = []
361+
362+ def compose (self ) -> ComposeResult :
363+ yield Button ("OK" )
364+
365+ @on (Enter , "Button" )
366+ @on (Leave , "Button" )
367+ def record (self , event : Enter | Leave ) -> None :
368+ self .messages .append (event .__class__ .__name__ )
369+
370+ app = EnterLeaveApp ()
371+ async with app .run_test () as pilot :
372+ expected_messages = []
373+
374+ await pilot .hover (Button )
375+ expected_messages .append ("Enter" )
376+ assert app .messages == expected_messages
377+
378+ await pilot .hover (Button , offset = (0 , 20 ))
379+ expected_messages .append ("Leave" )
380+ assert app .messages == expected_messages
You can’t perform that action at this time.
0 commit comments