Skip to content

Commit 6dabbca

Browse files
committed
multi line label
1 parent a073be8 commit 6dabbca

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/textual/widgets/_button.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ def __init__(
206206
"""Amount of time in seconds the button 'press' animation lasts."""
207207

208208
def get_content_width(self, container: Size, viewport: Size) -> int:
209-
return cell_len(str(self.label)) + 2
209+
try:
210+
return max([cell_len(line) for line in self.label.plain.splitlines()]) + 2
211+
except ValueError:
212+
# Empty string label
213+
return 2
210214

211215
def __rich_repr__(self) -> rich.repr.Result:
212216
yield from super().__rich_repr__()

0 commit comments

Comments
 (0)