Skip to content

Commit

Permalink
simpler fix
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 9, 2024
1 parent 963149f commit 70d42b3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/textual/widgets/_option_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ async def _on_click(self, event: events.Click) -> None:
event: The click event.
"""
clicked_option: int | None = event.style.meta.get("option")
if clicked_option is not None and not self._options[clicked_option].disabled:
if (
clicked_option is not None
and clicked_option >= 0
and not self._options[clicked_option].disabled
):
self.highlighted = clicked_option
self.action_select()

Expand Down Expand Up @@ -454,11 +458,9 @@ def _render_option_content(
renderable = Padding(renderable, padding)
lines = self.app.console.render_lines(renderable, options, style=style)

if option_index == -1:
strips = [Strip(line, width) for line in lines]
else:
style_meta = Style.from_meta({"option": option_index})
strips = [Strip(line, width).apply_style(style_meta) for line in lines]
style_meta = Style.from_meta({"option": option_index})
strips = [Strip(line, width).apply_style(style_meta) for line in lines]

self._content_render_cache[cache_key] = strips
return strips

Expand Down

0 comments on commit 70d42b3

Please sign in to comment.