Giter Club home page Giter Club logo

Comments (5)

TomJGooding avatar TomJGooding commented on September 24, 2024 2

Related issue:

I'm not suggesting this should be marked as duplicate, rather just trying to link this to the overarching issue.

from textual.

davep avatar davep commented on September 24, 2024 1

While the "scroll into view when activated" thing was a nice and easy one-liner; the TabbedContent.TabActivated issue is a bit trickier at first glance. It's very deliberately not done in the code, most likely because of the Catch-22 of a change to TabbedContent.active causing a change to Tabs.active which does post a Tabs.Activated, which in turn triggers TabbedContent._on_tabs_tab_activated, which in turn assigns TabbedContent.active, which would force the TabbedContent.active watcher, which would...

Unless I'm missing the obvious (highly likely) this might take a bit more than one line to work around.

from textual.

davep avatar davep commented on September 24, 2024

Using the following code we can see that the "scroll tab into view" problem stems from Tabs:

from textual import on
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import TabbedContent, TabPane, Tabs, Tab, Label, Log, Rule

class TabbedContentActiveApp(App[None]):

    BINDINGS = [
        ("c", "jump_tabbed_content"),
        ("t", "jump_tabs")
    ]

    def compose(self) -> ComposeResult:
        with Vertical() as container:
            container.border_title = "TabbedContent version"
            with TabbedContent():
                for n in range(200):
                    with TabPane(f"Filler {n}", id=f"filler-{n}"):
                        yield Label(f"Filler tab {n}")
                with TabPane("PICK ME!", id="pick-me"):
                    yield Label("This is the tab we're after")
        with Vertical() as container:
            container.border_title = "Tabs version"
            yield Tabs(
                *(
                    tuple(Tab(f"Filler {n}", id=f"filler-{n}") for n in range(200)) +
                    (Tab("PICK ME!", id="pick-me"),)
                )
            )
        yield Rule()
        yield Log()

    @on(TabbedContent.TabActivated)
    @on(Tabs.TabActivated)
    def log_messages(self, event: TabbedContent.TabActivated | Tabs.TabActivated) -> None:
        self.query_one(Log).write_line(f"{event!r}")

    def action_jump_tabbed_content(self) -> None:
        self.query_one(TabbedContent).active = "pick-me"

    def action_jump_tabs(self) -> None:
        self.query_one("Vertical > Tabs", Tabs).active = "pick-me"

if __name__ == "__main__":
    TabbedContentActiveApp().run()

We can also see that Tabs does post the relevant message when active is set, so most likely TabbedContent isn't handling that situation correctly.

from textual.

charles-001 avatar charles-001 commented on September 24, 2024

@davep - that makes sense. My main issue was actually the active tab not coming into view which you've fixed :) Thank you!

from textual.

github-actions avatar github-actions commented on September 24, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

from textual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.