fix auto width select

This commit is contained in:
Will McGugan
2024-11-24 20:27:10 +00:00
parent df8ffb12d2
commit 2b9dee032e
3 changed files with 38 additions and 1 deletions

View File

@@ -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
## [0.87.0] - 2024-11-24

View File

@@ -380,8 +380,10 @@ class OptionList(ScrollView, can_focus=True):
"""Get maximum width of options."""
console = self.app.console
options = console.options
padding = self.get_component_styles("option-list--option").padding
padding_width = padding.width
return max(
Measurement.get(console, options, option.prompt).maximum
Measurement.get(console, options, option.prompt).maximum + padding_width
for option in self._options
)

View File

@@ -2715,3 +2715,37 @@ def test_grid_offset(snap_compare):
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)