Skip to content
Discussion options

You must be logged in to vote

1. Focusing a newly mounted widget

mount() doesn't mount the widget straight away. It schedules the mount and returns an AwaitMount. If you await it, the widget is fully mounted (it's in the DOM and has run on_mount) before your next line runs. Actions can be async, so the usual way to write this is:

async def action_foo(self) -> None:
    table = DataTable()
    await self.mount(table)
    table.focus()

Your version without the await usually works too. Widget.focus() doesn't move focus immediately; it schedules the change with call_later, which normally runs after the mount has finished. That depends on timing, though, which is probably where the glitch reports come from. Awaiting the mo…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@calestyo
Comment options

@calestyo
Comment options

@pyrrhonic
Comment options

@calestyo
Comment options

Answer selected by calestyo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants