Skip to content

Commit 3a8eedd

Browse files
authored
Merge pull request #5282 from Textualize/select-width-auto
fix auto width select
2 parents df8ffb1 + 476c16a commit 3a8eedd

File tree

5 files changed

+202
-4
lines changed

5 files changed

+202
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
## Fixed
1111

1212
- Fixed offset not being applied to grid layout https://github.com/Textualize/textual/pull/5281
13+
- Fixed Select overlay set to auto width https://github.com/Textualize/textual/pull/5282
1314

1415
## [0.87.0] - 2024-11-24
1516

@@ -2581,6 +2582,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
25812582
- New handler system for messages that doesn't require inheritance
25822583
- Improved traceback handling
25832584

2585+
[0.87.1]: https://github.com/Textualize/textual/compare/v0.87.0...v0.87.1
25842586
[0.87.0]: https://github.com/Textualize/textual/compare/v0.86.4...v0.87.0
25852587
[0.86.3]: https://github.com/Textualize/textual/compare/v0.86.2...v0.86.3
25862588
[0.86.2]: https://github.com/Textualize/textual/compare/v0.86.1...v0.86.2

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "0.87.0"
3+
version = "0.87.1"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/widgets/_option_list.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,14 @@ def get_content_width(self, container: Size, viewport: Size) -> int:
380380
"""Get maximum width of options."""
381381
console = self.app.console
382382
options = console.options
383-
return max(
384-
Measurement.get(console, options, option.prompt).maximum
385-
for option in self._options
383+
padding = self.get_component_styles("option-list--option").padding
384+
padding_width = padding.width
385+
return (
386+
max(
387+
Measurement.get(console, options, option.prompt).maximum
388+
for option in self._options
389+
)
390+
+ padding_width
386391
)
387392

388393
def get_content_height(self, container: Size, viewport: Size, width: int) -> int:

tests/snapshot_tests/__snapshots__/test_snapshots/test_select_width_auto.svg

Lines changed: 157 additions & 0 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,3 +2715,37 @@ def compose(self) -> ComposeResult:
27152715
yield Static("Six", classes="box", id="six")
27162716

27172717
assert snap_compare(GridOffsetApp())
2718+
2719+
2720+
def test_select_width_auto(snap_compare):
2721+
"""Regression test for https://github.com/Textualize/textual/issues/5280"
2722+
The overlay has a width of auto, so the first (widest) option should not wrap."""
2723+
2724+
class TallSelectApp(App[None]):
2725+
CSS = """
2726+
Screen {
2727+
align: center middle;
2728+
2729+
& > Select {
2730+
width: 50;
2731+
2732+
& > SelectOverlay {
2733+
max-height: 100vh;
2734+
width: auto;
2735+
}
2736+
}
2737+
}
2738+
"""
2739+
2740+
def compose(self) -> ComposeResult:
2741+
yield Select(
2742+
[("Extra long option here", 100)]
2743+
+ [(f"Option {idx + 1}", idx) for idx in range(100)],
2744+
value=25,
2745+
)
2746+
2747+
async def run_before(pilot: Pilot) -> None:
2748+
await pilot.pause()
2749+
await pilot.click("Select")
2750+
2751+
snap_compare(TallSelectApp(), run_before=run_before)

0 commit comments

Comments
 (0)