Skip to content

Input should release mouse when screen is changed #5899

@willmcgugan

Description

@willmcgugan

Discussed in #5897

Originally posted by BenniWi June 25, 2025
Hi everyone,

to be honest I'm not sure if I found a bug or if I'm doing something wrong. I checked the FAQs and the manual but could not find anything.

The bug

Using the below minimal example (stripped down from my actual programm), I'm creating multiple screens on top of each other.
Clicking the "click me" button will open a new screen. In then screen I want to push a new screen when entering the second "Input" with the text "blub1; blub2".
As soon as I focus on the Input, the new screen is pushed.
But from that moment on I can not do anything anymore, the app is basically stuck.

I'm using textual 3.5.0 (and 3.2.0) and I know it worked once with an older version (2.1.2)
The minimal example is:

from textual import on
from textual.app import App, ComposeResult
from textual.containers import Container, Grid
from textual.events import DescendantFocus
from textual.screen import ModalScreen
from textual.widgets import (
    Button,
    Input,
)


class OnFocusScreen(ModalScreen):

    def compose(self) -> ComposeResult:
        yield Grid(
            Button("A", variant="error", id="A"),
            id="dialog",
        )

    def on_button_pressed(self, event: Button.Pressed) -> None:
        self.dismiss()


class OnClickScreen(ModalScreen):

    def compose(self) -> ComposeResult:
        yield Grid(
            Input(
                id="test_input",
                value="abcd",
            ),
            Input(
                id="focus_test_input",
                value="focus me",
            ),
            id="new-entry-dialog",
        )

    @on(DescendantFocus, "#focus_test_input")
    def labels_input_focused(self) -> None:
        self.app.push_screen(OnFocusScreen())


class FocusTestApp(App):
    def compose(self) -> ComposeResult:
        with Container(id="focus_test_ui"):
            yield Button("click_me", id="clickme", variant="primary")

    @on(Button.Pressed, "#clickme")
    def pressed_new(self, event: Button.Pressed) -> None:
        self.push_screen(OnClickScreen())
        # self.push_screen(OnFocusScreen())


def main():
    FocusTestApp().run(inline=False)


if __name__ == "__main__":
    main()

Thanks a lot for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions