diff --git a/src/textual/app.py b/src/textual/app.py index 03e728ac9..43f1bd56c 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -632,6 +632,12 @@ class App(Generic[ReturnType], DOMNode): print(f"press {key!r} (char={char!r})") key_event = events.Key(self, key, char) driver.send_event(key_event) + # TODO: A bit of a fudge - extra sleep after tabbing to help guard against race + # condition between widget-level key handling and app/screen level handling. + # More information here: https://github.com/Textualize/textual/issues/1009 + # This conditional sleep can be removed after that issue is closed. + if key == "tab": + await asyncio.sleep(0.05) await asyncio.sleep(0.02) await app._animator.wait_for_idle() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 5831e0b78..d68bb5c21 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -58,9 +58,9 @@ def test_checkboxes(snap_compare): def test_input_and_focus(snap_compare): press = [ "tab", - *list("Darren"), # Focus first input, write "Darren" + *"Darren", # Focus first input, write "Darren" "tab", - *list("Burns"), # Tab focus to second input, write "Burns" + *"Burns", # Tab focus to second input, write "Burns" ] assert snap_compare("docs/examples/widgets/input.py", press=press)