Skip to content

Commit eab55f0

Browse files
committed
compact snapshot
1 parent 5d157d3 commit eab55f0

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Added
1515

1616
- Added `toggle_class` parameter to reactives
17-
- Added `compact` parameter and reactive to `Button`, `Input`, `ToggleButton`, `RadioSet`, `OptionList`
17+
- Added `compact` parameter and reactive to `Button`, `Input`, `ToggleButton`, `RadioSet`, `OptionList`, `TextArea`
1818

1919
### Changed
2020

src/textual/widgets/_text_area.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class TextArea(ScrollView):
113113
padding: 0 1;
114114
color: $foreground;
115115
background: $surface;
116+
&.-textual-compact {
117+
border: none !important;
118+
}
116119
& .text-area--cursor {
117120
text-style: $input-cursor-text-style;
118121
}
@@ -368,6 +371,9 @@ class TextArea(ScrollView):
368371
The document can still be edited programmatically via the API.
369372
"""
370373

374+
compact: reactive[bool] = reactive(False, toggle_class="-textual-compact")
375+
"""Enable compact display?"""
376+
371377
_cursor_visible: Reactive[bool] = reactive(False, repaint=False, init=False)
372378
"""Indicates where the cursor is in the blink cycle. If it's currently
373379
not visible due to blinking, this is False."""
@@ -420,6 +426,7 @@ def __init__(
420426
classes: str | None = None,
421427
disabled: bool = False,
422428
tooltip: RenderableType | None = None,
429+
compact: bool = False,
423430
) -> None:
424431
"""Construct a new `TextArea`.
425432
@@ -438,6 +445,7 @@ def __init__(
438445
classes: One or more Textual CSS compatible class names separated by spaces.
439446
disabled: True if the widget is disabled.
440447
tooltip: Optional tooltip.
448+
compact: Enable compact style (without borders).
441449
"""
442450
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
443451

@@ -512,6 +520,8 @@ def __init__(
512520
if tooltip is not None:
513521
self.tooltip = tooltip
514522

523+
self.compact = compact
524+
515525
@classmethod
516526
def code_editor(
517527
cls,
@@ -530,6 +540,7 @@ def code_editor(
530540
classes: str | None = None,
531541
disabled: bool = False,
532542
tooltip: RenderableType | None = None,
543+
compact: bool = False,
533544
) -> TextArea:
534545
"""Construct a new `TextArea` with sensible defaults for editing code.
535546
@@ -549,6 +560,7 @@ def code_editor(
549560
classes: One or more Textual CSS compatible class names separated by spaces.
550561
disabled: True if the widget is disabled.
551562
tooltip: Optional tooltip
563+
compact: Enable compact style (without borders).
552564
"""
553565
return cls(
554566
text,
@@ -565,6 +577,7 @@ def code_editor(
565577
classes=classes,
566578
disabled=disabled,
567579
tooltip=tooltip,
580+
compact=compact,
568581
)
569582

570583
@staticmethod

tests/snapshot_tests/test_snapshots.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,3 +4021,36 @@ def compose(self) -> ComposeResult:
40214021
yield Label("Hello, World")
40224022

40234023
assert snap_compare(TintApp())
4024+
4025+
4026+
def test_compact(snap_compare):
4027+
"""Test compact styles.
4028+
4029+
You should see a screen split vertically.
4030+
4031+
The left side has regular widgets, the right side has the corresponding compact widgets.
4032+
4033+
"""
4034+
4035+
class CompactApp(App):
4036+
4037+
def compose(self) -> ComposeResult:
4038+
with Horizontal():
4039+
4040+
with Vertical():
4041+
yield Button("Foo")
4042+
yield Input("hello")
4043+
yield Select.from_values(["Foo", "Bar"])
4044+
yield RadioSet("FOO", "BAR")
4045+
yield SelectionList(("FOO", "FOO"), ("BAR", "BAR"))
4046+
yield TextArea("Edit me")
4047+
4048+
with Vertical():
4049+
yield Button("Bar", compact=True)
4050+
yield Input("world", compact=True)
4051+
yield Select.from_values(["Foo", "Bar"], compact=True)
4052+
yield RadioSet("FOO", "BAR", compact=True)
4053+
yield SelectionList(("FOO", "FOO"), ("BAR", "BAR"), compact=True)
4054+
yield TextArea("Edit me", compact=True)
4055+
4056+
assert snap_compare(CompactApp())

0 commit comments

Comments
 (0)