Skip to content

Commit 2b9dee0

Browse files
committed
fix auto width select
1 parent df8ffb1 commit 2b9dee0

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 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
1314

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

src/textual/widgets/_option_list.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,10 @@ 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+
padding = self.get_component_styles("option-list--option").padding
384+
padding_width = padding.width
383385
return max(
384-
Measurement.get(console, options, option.prompt).maximum
386+
Measurement.get(console, options, option.prompt).maximum + padding_width
385387
for option in self._options
386388
)
387389

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)