Skip to content
Discussion options

You must be logged in to vote

The issue was that the OptionList didn't have an opertunity to process the key bindings. Responding to the OptionList.OptionHighlighted event as @davep suggested will ensure that your code runs when the highlight changes.

This code reproduces the issue (and includes the solution).

from textual.app import App, ComposeResult
from textual.widgets import OptionList
from textual.widgets.option_list import Option
from textual import events
from textual import on


class ListWidget(OptionList):
    def on_mount(self) -> None:
        self.add_option(Option("1"))

    def on_key(self, event: events.Key) -> None:
        print(f"highlighted: {self.highlighted}")

    @on(OptionList.OptionHighlighted)

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by davep
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #2856 on June 28, 2023 10:00.