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

Focussing a widget inside a tab should switch tabs #4593

Closed
darrenburns opened this issue Jun 4, 2024 · 4 comments · Fixed by #4599
Closed

Focussing a widget inside a tab should switch tabs #4593

darrenburns opened this issue Jun 4, 2024 · 4 comments · Fixed by #4599

Comments

@darrenburns
Copy link
Member

Right now the widget gets focused, but it's not visible.

Note that there can be many layers of tabs.

DescendantFocus might come in handy.

@TomJGooding
Copy link
Contributor

TomJGooding commented Jun 4, 2024

I assume you mean when focusing a widget programmatically. Is my quick attempt at an example below a fair representation of this issue, where you would expect the tabs to switch automatically?

from textual.app import App, ComposeResult
from textual.widgets import Button, Footer, TabbedContent, TabPane


class ExampleApp(App):
    BINDINGS = [("space", "focus_button_2_2", "Focus button 2.2")]

    def compose(self) -> ComposeResult:
        with TabbedContent(id="tabbed-root"):
            with TabPane("[red]Parent 1[/]"):
                with TabbedContent():
                    with TabPane("[red]Child 1.1[/]"):
                        yield Button("Button 1.1", variant="error")
                    with TabPane("[red]Child 1.2[/]"):
                        yield Button("Button 1.2", variant="error")

            with TabPane("[green]Parent 2[/]", id="parent-2"):
                with TabbedContent(id="tabbed-parent-2"):
                    with TabPane("[green]Child 2.1[/]"):
                        yield Button("Button 2.1", variant="success")
                    with TabPane("[green]Child 2.2[/]", id="child-2-2"):
                        yield Button(
                            "Button 2.2",
                            variant="success",
                            id="button-2-2",
                        )

        yield Footer()

    def action_focus_button_2_2(self) -> None:
        # self.query_one("#tabbed-root", TabbedContent).active = "parent-2"
        # self.query_one("#tabbed-parent-2", TabbedContent).active = "child-2-2"

        self.query_one("#button-2-2", Button).focus()


if __name__ == "__main__":
    app = ExampleApp()
    app.run()

@darrenburns
Copy link
Member Author

@TomJGooding Yes - I mean programmatically. Looks like your example captures it :)

@willmcgugan
Copy link
Collaborator

That's for the MRE Tom!

Copy link

github-actions bot commented Jun 4, 2024

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

Successfully merging a pull request may close this issue.

3 participants