File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121- Added widgets.Digit https://github.com/Textualize/textual/pull/3073
2222- Added ` BORDER_TITLE ` and ` BORDER_SUBTITLE ` classvars to Widget https://github.com/Textualize/textual/pull/3097
2323
24+ ### Changed
25+ - DescendantBlur and DescendantFocus can now be used with @on decorator
26+
2427## [ 0.32.0] - 2023-08-03
2528
2629### Added
Original file line number Diff line number Diff line change 1313
1414from __future__ import annotations
1515
16+ from dataclasses import dataclass
1617from typing import TYPE_CHECKING , Type , TypeVar
1718
1819import rich .repr
@@ -547,21 +548,39 @@ class Blur(Event, bubble=False):
547548 """
548549
549550
551+ @dataclass
550552class DescendantFocus (Event , bubble = True , verbose = True ):
551553 """Sent when a child widget is focussed.
552554
553555 - [X] Bubbles
554556 - [X] Verbose
555557 """
556558
559+ widget : Widget
560+ """The widget that was focused."""
557561
562+ @property
563+ def control (self ) -> Widget :
564+ """The widget that was focused (alias of `widget`)."""
565+ return self .widget
566+
567+
568+ @dataclass
558569class DescendantBlur (Event , bubble = True , verbose = True ):
559570 """Sent when a child widget is blurred.
560571
561572 - [X] Bubbles
562573 - [X] Verbose
563574 """
564575
576+ widget : Widget
577+ """The widget that was blurred."""
578+
579+ @property
580+ def control (self ) -> Widget :
581+ """The widget that was blurred (alias of `widget`)."""
582+ return self .widget
583+
565584
566585@rich .repr .auto
567586class Paste (Event , bubble = True ):
Original file line number Diff line number Diff line change @@ -3290,12 +3290,14 @@ def _on_enter(self, event: events.Enter) -> None:
32903290 def _on_focus (self , event : events .Focus ) -> None :
32913291 self .has_focus = True
32923292 self .refresh ()
3293- self .post_message (events .DescendantFocus ())
3293+ if self .parent is not None :
3294+ self .parent .post_message (events .DescendantFocus (self ))
32943295
32953296 def _on_blur (self , event : events .Blur ) -> None :
32963297 self .has_focus = False
32973298 self .refresh ()
3298- self .post_message (events .DescendantBlur ())
3299+ if self .parent is not None :
3300+ self .parent .post_message (events .DescendantBlur (self ))
32993301
33003302 def _on_mouse_scroll_down (self , event : events .MouseScrollDown ) -> None :
33013303 if event .ctrl or event .shift :
You can’t perform that action at this time.
0 commit comments