diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c41a921e..53417a21fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixed - Fixed offset not being applied to grid layout https://github.com/Textualize/textual/pull/5281 +- Fixed Select overlay set to auto width https://github.com/Textualize/textual/pull/5282 ## [0.87.0] - 2024-11-24 @@ -2581,6 +2582,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040 - New handler system for messages that doesn't require inheritance - Improved traceback handling +[0.87.1]: https://github.com/Textualize/textual/compare/v0.87.0...v0.87.1 [0.87.0]: https://github.com/Textualize/textual/compare/v0.86.4...v0.87.0 [0.86.3]: https://github.com/Textualize/textual/compare/v0.86.2...v0.86.3 [0.86.2]: https://github.com/Textualize/textual/compare/v0.86.1...v0.86.2 diff --git a/pyproject.toml b/pyproject.toml index b21f182d1c..dae6c42efa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual" -version = "0.87.0" +version = "0.87.1" homepage = "https://github.com/Textualize/textual" repository = "https://github.com/Textualize/textual" documentation = "https://textual.textualize.io/" diff --git a/src/textual/widgets/_option_list.py b/src/textual/widgets/_option_list.py index 76bfd07415..cf99b8bf6e 100644 --- a/src/textual/widgets/_option_list.py +++ b/src/textual/widgets/_option_list.py @@ -380,9 +380,14 @@ 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 + padding = self.get_component_styles("option-list--option").padding + padding_width = padding.width + return ( + max( + Measurement.get(console, options, option.prompt).maximum + for option in self._options + ) + + padding_width ) def get_content_height(self, container: Size, viewport: Size, width: int) -> int: diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_select_width_auto.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_select_width_auto.svg new file mode 100644 index 0000000000..8450289ab9 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_select_width_auto.svg @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TallSelectApp + + + + + + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +Select + Extra long option here  + Option 1                + Option 2                + Option 3               ▂▂ + Option 4                + Option 5                + Option 6                + Option 7                + Option 8               ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + Option 9                + Option 10              ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + Option 11               + Option 12               + Option 13               + Option 14               + Option 15               + Option 16               + Option 17               + Option 18               + Option 19               + Option 20               +▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 265a2e2c6e..19b2155364 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -2715,3 +2715,37 @@ def compose(self) -> ComposeResult: yield Static("Six", classes="box", id="six") assert snap_compare(GridOffsetApp()) + + +def test_select_width_auto(snap_compare): + """Regression test for https://github.com/Textualize/textual/issues/5280" + The overlay has a width of auto, so the first (widest) option should not wrap.""" + + class TallSelectApp(App[None]): + CSS = """ + Screen { + align: center middle; + + & > Select { + width: 50; + + & > SelectOverlay { + max-height: 100vh; + width: auto; + } + } + } + """ + + def compose(self) -> ComposeResult: + yield Select( + [("Extra long option here", 100)] + + [(f"Option {idx + 1}", idx) for idx in range(100)], + value=25, + ) + + async def run_before(pilot: Pilot) -> None: + await pilot.pause() + await pilot.click("Select") + + snap_compare(TallSelectApp(), run_before=run_before)