diff --git a/CHANGELOG.md b/CHANGELOG.md
index 78857f76c..570b5be1c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Programmatically setting `overflow_x`/`overflow_y` refreshes the layout correctly https://github.com/Textualize/textual/issues/1616
- Fixed double-paste into `Input` https://github.com/Textualize/textual/issues/1657
- Added a workaround for an apparent Windows Terminal paste issue https://github.com/Textualize/textual/issues/1661
+- Fixes issue with renderable width calculation https://github.com/Textualize/textual/issues/1685
## [0.10.1] - 2023-01-20
diff --git a/src/textual/render.py b/src/textual/render.py
index 611ee4420..6d5dbc326 100644
--- a/src/textual/render.py
+++ b/src/textual/render.py
@@ -2,13 +2,20 @@ from rich.console import Console, RenderableType
from rich.protocol import rich_cast
-def measure(console: Console, renderable: RenderableType, default: int) -> int:
+def measure(
+ console: Console,
+ renderable: RenderableType,
+ default: int,
+ *,
+ container_width: int | None = None
+) -> int:
"""Measure a rich renderable.
Args:
console: A console object.
renderable: Rich renderable.
default: Default width to use if renderable does not expose dimensions.
+ container_width: Width of container or None to use console width.
Returns:
Width in cells
@@ -17,6 +24,13 @@ def measure(console: Console, renderable: RenderableType, default: int) -> int:
renderable = rich_cast(renderable)
get_console_width = getattr(renderable, "__rich_measure__", None)
if get_console_width is not None:
- render_width = get_console_width(console, console.options).maximum
+ render_width = get_console_width(
+ console,
+ (
+ console.options
+ if container_width is None
+ else console.options.update_width(container_width)
+ ),
+ ).maximum
width = max(0, render_width)
return width
diff --git a/src/textual/widget.py b/src/textual/widget.py
index d2d78c14b..4b2a6973f 100644
--- a/src/textual/widget.py
+++ b/src/textual/widget.py
@@ -795,7 +795,9 @@ class Widget(DOMNode):
console = self.app.console
renderable = self._render()
- width = measure(console, renderable, container.width)
+ width = measure(
+ console, renderable, container.width, container_width=container.width
+ )
if self.expand:
width = max(container.width, width)
if self.shrink:
diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
index 1883f87a2..bcc99b64d 100644
--- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
+++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
@@ -12380,6 +12380,165 @@
'''
# ---
+# name: test_label_wrap
+ '''
+
+
+ '''
+# ---
# name: test_layers
'''