MCPcopy
hub / github.com/Textualize/textual / test_get_focusable_widget_at

Function test_get_focusable_widget_at

tests/test_focus.py:431–467  ·  view source on GitHub ↗

Check that clicking a non-focusable widget will focus any (focusable) ancestors.

()

Source from the content-addressed store, hash-verified

429
430
431async def test_get_focusable_widget_at() -> None:
432 """Check that clicking a non-focusable widget will focus any (focusable) ancestors."""
433
434 class FocusApp(App):
435 AUTO_FOCUS = None
436
437 def compose(self) -> ComposeResult:
438 with ScrollableContainer(id="focusable"):
439 with Container():
440 yield Label("Foo", id="foo")
441 yield Label("Bar", id="bar")
442 yield Label("Egg", id="egg")
443
444 app = FocusApp()
445 async with app.run_test() as pilot:
446 # Nothing focused
447 assert app.screen.focused is None
448 # Click foo
449 await pilot.click("#foo")
450 # Confirm container is focused
451 assert app.screen.focused is not None
452 assert app.screen.focused.id == "focusable"
453 # Reset focus
454 app.screen.set_focus(None)
455 assert app.screen.focused is None
456 # Click bar
457 await pilot.click("#bar")
458 # Confirm container is focused
459 assert app.screen.focused is not None
460 assert app.screen.focused.id == "focusable"
461 # Reset focus
462 app.screen.set_focus(None)
463 assert app.screen.focused is None
464 # Click egg (outside of focusable widget)
465 await pilot.click("#egg")
466 # Confirm nothing focused
467 assert app.screen.focused is None
468
469
470async def test_allow_focus_override():

Callers

nothing calls this directly

Calls 4

run_testMethod · 0.80
clickMethod · 0.80
FocusAppClass · 0.70
set_focusMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…