From 714736942607f0cf385a095a731609bf30399523 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 11 May 2024 17:13:06 +0100 Subject: [PATCH 1/2] add get_content_width --- src/textual/widgets/_option_list.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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: From 7e9c4c8c885c988cf168f0a709eeb432bd417057 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 11 May 2024 17:14:19 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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