Additional sleep after tabbing to guard vs races

This commit is contained in:
Darren Burns
2022-10-25 10:57:54 +01:00
parent 5adbba7674
commit 617f0acb99
2 changed files with 8 additions and 2 deletions

View File

@@ -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()

View File

@@ -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)