mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix auto width select
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user