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

OptionList sizing issue #4531

Open
willmcgugan opened this issue May 20, 2024 · 1 comment
Open

OptionList sizing issue #4531

willmcgugan opened this issue May 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@willmcgugan
Copy link
Collaborator

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()
@darrenburns
Copy link
Member

Confirmed this is still an issue.

To be clear the issue is when the you add a bunch of items using the code above (pressing enter), when the option list gets to the bottom of the screen it sometimes is scrolled partially out of bounds.

@darrenburns darrenburns added the bug Something isn't working label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants