Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Focused Input Widget inside a composed ListItem immediately loses focus #5391

Closed
Zaloog opened this issue Dec 13, 2024 · 4 comments
Closed

Comments

@Zaloog
Copy link
Contributor

Zaloog commented Dec 13, 2024

If I create a custom ListItem with an Input Widget, it immediately loses focus when selected, writing into it is not possible, except by clicking and holding the mouse down while writing. I tested the same MRE with v0.88.0, focusing the Input worked there.

MRE:

from textual.app import App
from textual.widgets import ListView, ListItem, Input, Button
from textual.containers import Horizontal


class CustomListItem(ListItem):
    def compose(self):
        with Horizontal():
            yield Input(placeholder='Text Here')
            yield Button(label='Text Here')


class MREApp(App):
    DEFAULT_CSS = """

    ListView {
        height:auto;
        width:1fr;
    }
    CustomListItem {
        height:auto;
        width:1fr;

        Horizontal {
            width:1fr;
            height:auto;
            
            Input {
                height:auto;
                width:3fr;
            }
            Button {
                height:auto;
                width:1fr;
            }
        }
    }
    """
    def compose(self):
        yield ListView(
            * [CustomListItem() for _ in range(3)]

        )
if __name__ == '__main__':
    app = MREApp()
    app.run()
# Textual Diagnostics

## Versions

| Name    | Value  |
|---------|--------|
| Textual | 1.0.0  |
| Rich    | 13.9.4 |

## Python

| Name           | Value                                                   |
|----------------|---------------------------------------------------------|
| Version        | 3.13.1                                                  |
| Implementation | CPython                                                 |
| Compiler       | Clang 16.0.0 (clang-1600.0.26.4)                        |
| Executable     | /Users/zaloog/Desktop/repos/kanban-tui/.venv/bin/python |

## Operating System

| Name    | Value                                                                                                  |
|---------|--------------------------------------------------------------------------------------------------------|
| System  | Darwin                                                                                                 |
| Release | 24.1.0                                                                                                 |
| Version | Darwin Kernel Version 24.1.0: Thu Nov 14 18:15:21 PST 2024; root:xnu-11215.41.3~13/RELEASE_ARM64_T6041 |

## Terminal

| Name                 | Value         |
|----------------------|---------------|
| Terminal Application | tmux (3.5a)   |
| TERM                 | tmux-256color |
| COLORTERM            | truecolor     |
| FORCE_COLOR          | *Not set*     |
| NO_COLOR             | *Not set*     |

## Rich Console options

| Name           | Value                |
|----------------|----------------------|
| size           | width=140, height=55 |
| legacy_windows | False                |
| min_width      | 1                    |
| max_width      | 140                  |
| is_terminal    | False                |
| encoding       | utf-8                |
| max_height     | 55                   |
| justify        | None                 |
| overflow       | None                 |
| no_wrap        | False                |
| highlight      | None                 |
| markup         | None                 |
| height         | None                 |


Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@Zaloog Zaloog changed the title [BUG] Focusing an Input Widget inside a composed ListItem is no longer possible [BUG] Focused Input Widget inside a composed ListItem immediately loses focus Dec 13, 2024
@TomJGooding
Copy link
Contributor

TomJGooding commented Dec 14, 2024

I don't think this reliably works in earlier versions of Textual either. If you try clicking between the different Inputs a few times, sometimes the click will focus the outer ListView rather than the Input widget.

I understand this is only a MRE, but do you actually need to use ListView rather than a simple container?

@Zaloog
Copy link
Contributor Author

Zaloog commented Dec 14, 2024

Nah I could use a container too, would also be more appropriate

@Zaloog Zaloog closed this as completed Dec 19, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants