Clicking the Header makes it tall, but `Header.tall` stays False

Open
#6,771 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
frontend

Research direction

The header widget lives in src/textual/widgets/_header.py; read _on_click there next to watch_tall, which is what actually applies the -tall class when the reactive changes. Run the snippet from the issue against a checkout to confirm the mismatch, then check the existing header tests (and snapshot tests under tests/) for where to add a regression case. Done means a click sets tall to True and header.tall = False shrinks the header back to one line. Note the reporter says a PR with a test is already prepared, so coordinate before starting.

Written by the indexing model from the issue text.

Description

Hi! I hit this while writing generated tests against Textual's widgets.

Header._on_click toggles the -tall class directly, rather than the tall reactive that watch_tall uses to set that class. So after a click the header is drawn tall but tall is still False, and header.tall = False does nothing, because the value hasn't changed.

import asyncio

import textual
from textual.app import App, ComposeResult
from textual.widgets import Header

class HeaderApp(App):
    def compose(self) -> ComposeResult:
        yield Header()

async def main() -> None:
    app = HeaderApp()
    async with app.run_test() as pilot:
        header = app.query_one(Header)
        await pilot.pause()
        print(f"start:              tall={header.tall} height={header.size.height} classes={sorted(header.classes)}")
        await pilot.click(offset=(40, 0))  # on the title
        await pilot.pause()
        print(f"after click:        tall={header.tall} height={header.size.height} classes={sorted(header.classes)}")
        header.tall = False
        await pilot.pause()
        print(f"after tall = False: tall={header.tall} height={header.size.height} classes={sorted(header.classes)}")
    print("Textual", textual.__version__)

asyncio.run(main())

Output on Textual 8.2.7 (and the same on main at 5e5b7ef):

start:              tall=False height=1 classes=[]
after click:        tall=False height=3 classes=['-tall']
after tall = False: tall=False height=3 classes=['-tall']

I expected tall=True after the click, and the header to go back to one line after header.tall = False. Toggling the reactive in _on_click (self.tall = not self.tall) gives that, and I have a PR with a test ready if you'd like it.

Dominant language
Python
Stars
37.7k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Textualize/textual

All issues in Textualize/textual

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.