Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.73k stars 792 forks source link

`Select` initial value is out of view when first expanded #5255

Open TomJGooding opened 4 days ago

TomJGooding commented 4 days ago

When the Select widget is first expanded, the initial selected value is out of view when it appears further down in the list of options.

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

class SelectApp(App):
    def compose(self) -> ComposeResult:
        yield Select.from_values(
            range(20),
            value=15,
        )

if __name__ == "__main__":
    app = SelectApp()
    app.run()
github-actions[bot] commented 4 days ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

TomJGooding commented 4 days ago

I think the problem is when the Select is first expanded, where this calls OptionList.scroll_to_highlight the region values here are all zeros:

https://github.com/Textualize/textual/blob/8d99130708b3a862fc849884e0015c2c864345d1/src/textual/widgets/_option_list.py#L891-L896