diff --git a/CHANGELOG.md b/CHANGELOG.md index 134cc7e307..68cd1546ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed + +- Fixed auto width not working for option lists https://github.com/Textualize/textual/pull/4507 + ## [0.59.0] - 2024-05-11 ### Fixed diff --git a/src/textual/widgets/_option_list.py b/src/textual/widgets/_option_list.py index c59320afda..88665451b7 100644 --- a/src/textual/widgets/_option_list.py +++ b/src/textual/widgets/_option_list.py @@ -10,6 +10,7 @@ from typing import ClassVar, Iterable, NamedTuple from rich.console import RenderableType +from rich.measure import Measurement from rich.padding import Padding from rich.repr import Result from rich.rule import Rule @@ -360,6 +361,15 @@ def __init__( # the state of the option list in regard to its available options. self.action_first() + def get_content_width(self, container: Size, viewport: Size) -> int: + """Get maximum width of options.""" + console = self.app.console + options = console.options + return max( + Measurement.get(console, options, option.prompt).maximum + for option in self._options + ) + def _request_content_tracking_refresh( self, rescroll_to_highlight: bool = False ) -> None: