Skip to content

OptionList sizing issue #4531

@willmcgugan

Description

@willmcgugan

The OptionList delays it's size calculation, which means that this code breaks.

I think we can refactor it to calculate the virtual size without so many intermediate messages.

from textual.app import App, ComposeResult
from textual.widgets import OptionList, Label
from textual.containers import VerticalScroll
from textual.message import Message

class Wizard(App):

    def compose(self) -> ComposeResult:
        with VerticalScroll(id = "body") as scroller:
            scroller.can_focus = False
            self.body = scroller
            yield OptionList("yes","no")

    async def ask_yes_no(self):
        await self.body.mount_all([
            Label("some text"),
            query := OptionList("yes","no")
        ])
        query.focus()

    async def on_option_list_option_selected(self, message: OptionList.OptionSelected) -> None:
        await message.option_list.remove()
        await self.ask_yes_no()
        self.body.scroll_end(animate=False)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions