diff --git a/src/textual/app.py b/src/textual/app.py index a2bfca31e..c0f0f118e 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -239,6 +239,9 @@ class App(Generic[ReturnType], DOMNode): Args: direction (int, optional): 1 to move forward, -1 to move backward, or 0 to highlight the current focus. + + Returns: + Widget | None: Newly focused widget, or None for no focus. """ if self._focus_timer: # Cancel the timer that clears the show focus class @@ -270,19 +273,36 @@ class App(Generic[ReturnType], DOMNode): return self.focused def show_focus(self) -> Widget | None: - """Highlight the currently focused widget.""" + """Highlight the currently focused widget. + + Returns: + Widget | None: Focused widget, or None for no focus. + """ return self._move_focus(0) def focus_next(self) -> Widget | None: - """Focus the next widget.""" + """Focus the next widget. + + Returns: + Widget | None: Newly focused widget, or None for no focus. + """ return self._move_focus(1) def focus_previous(self) -> Widget | None: - """Focus the previous widget.""" + """Focus the previous widget. + + Returns: + Widget | None: Newly focused widget, or None for no focus. + """ return self._move_focus(-1) def hide_focus(self) -> None: - """Hide the focus.""" + """Hide the focus. + + Returns: + Widget | None: Newly focused widget, or None for no focus. + + """ self.remove_class("-show-focus") def compose(self) -> ComposeResult: diff --git a/tests/test_focus.py b/tests/test_focus.py index 167738494..db57cace1 100644 --- a/tests/test_focus.py +++ b/tests/test_focus.py @@ -11,7 +11,7 @@ class NonFocusable(Widget, can_focus=False): pass -def test_focus_chain(): +async def test_focus_chain(): app = App() app.push_screen(Screen()) @@ -31,7 +31,7 @@ def test_focus_chain(): assert focused == ["foo", "Paul", "baz"] -def test_show_focus(): +async def test_show_focus(): app = App() app.push_screen(Screen()) app.screen.add_children( @@ -51,7 +51,7 @@ def test_show_focus(): assert app.has_class("-show-focus") -def test_focus_next_and_previous(): +async def test_focus_next_and_previous(): app = App() app.push_screen(Screen())