From caab7d20dce351052878c6b0cb2eb34c2c4ba4ae Mon Sep 17 00:00:00 2001 From: Steve Holden Date: Sun, 22 Jun 2025 16:41:44 +0100 Subject: [PATCH 1/2] Honour the `valid_empty` flag even when `Input` has no validators. --- src/textual/widgets/_input.py | 17 ++++++++--------- tests/input/test_input_empty_valid.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 tests/input/test_input_empty_valid.py diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index 326e535958..8ad9e1b5c9 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -149,7 +149,7 @@ class Input(ScrollView): | ctrl+k | Delete everything to the right of the cursor. | | ctrl+x | Cut selected text. | | ctrl+c | Copy selected text. | - | ctrl+v | Paste text from the clipboard. | + | ctrl+v | Paste text from the clipboard. | """ COMPONENT_CLASSES: ClassVar[set[str]] = { @@ -187,9 +187,9 @@ class Input(ScrollView): } &:focus { - border: tall $border; + border: tall $border; background-tint: $foreground 5%; - + } &>.input--cursor { background: $input-cursor-background; @@ -207,12 +207,12 @@ class Input(ScrollView): } &.-invalid:focus { border: tall $error; - } + } &:ansi { background: ansi_default; color: ansi_default; - &>.input--cursor { + &>.input--cursor { text-style: reverse; } &>.input--placeholder, &>.input--suggestion { @@ -224,8 +224,8 @@ class Input(ScrollView): } &.-invalid:focus { border: tall ansi_red; - } - + } + } } @@ -417,8 +417,7 @@ def __init__( ``` """ self._reactive_valid_empty = valid_empty - self._valid = True - + self._valid = not (input and not valid_empty) self.restrict = restrict if type not in _RESTRICT_TYPES: raise ValueError( diff --git a/tests/input/test_input_empty_valid.py b/tests/input/test_input_empty_valid.py new file mode 100644 index 0000000000..6e9b80fac4 --- /dev/null +++ b/tests/input/test_input_empty_valid.py @@ -0,0 +1,17 @@ +from textual.app import App, ComposeResult +from textual.widgets import Input + + +class InputApp(App): + + def compose(self) -> ComposeResult: + yield Input(valid_empty=False) + + +async def test_cut(): + """Check that cut removes text and places it in the clipboard.""" + app = InputApp() + async with app.run_test() as pilot: + input = app.query_one(Input) + assert input.value == "" + assert not input.is_valid From 30df1336260a053e8731c6faa0d746fe4b821b67 Mon Sep 17 00:00:00 2001 From: Steve Holden Date: Tue, 24 Jun 2025 15:20:35 +0100 Subject: [PATCH 2/2] Update pre-commit hooks after autoupdate. --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 009c06616e..5e638e58bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,11 +24,11 @@ repos: language_version: '3.11' args: ['--profile', 'black', '--filter-files'] - repo: https://github.com/psf/black - rev: '24.1.1' + rev: '25.1.0' hooks: - id: black - repo: https://github.com/hadialqattan/pycln # removes unused imports - rev: v2.3.0 + rev: v2.5.0 hooks: - id: pycln language_version: '3.11'