Skip to content

Commit

Permalink
Merge pull request #5282 from Textualize/select-width-auto
Browse files Browse the repository at this point in the history
fix auto width select
  • Loading branch information
willmcgugan authored Nov 24, 2024
2 parents df8ffb1 + 476c16a commit 3a8eedd
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
11 changes: 8 additions & 3 deletions src/textual/widgets/_option_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3a8eedd

Please sign in to comment.