Repository: Textualize/textual

Issue:
[FEAT] Add `Input.clear` method
Following discussions in #3427, it would make sense to add a `Input.clear` method.

I'm happy to a submit a PR, if it helps.

Discussion:
willmcgugan: Thanks, Tom.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41d543fc8..a52f8df41 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 ### Added
 
 - `OutOfBounds` exception to be raised by `Pilot` https://github.com/Textualize/textual/pull/3360
+- Added `Input.clear` method https://github.com/Textualize/textual/pull/3430
 
 ### Changed
 
diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py
index b92161e50..c7603297e 100644
--- a/src/textual/widgets/_input.py
+++ b/src/textual/widgets/_input.py
@@ -481,6 +481,10 @@ class Input(Widget, can_focus=True):
             self.value = f"{before}{text}{after}"
             self.cursor_position += len(text)
 
+    def clear(self) -> None:
+        """Clear the input."""
+        self.value = ""
+
     def action_cursor_left(self) -> None:
         """Move the cursor one position to the left."""
         self.cursor_position -= 1


Test patch:
diff --git a/tests/input/test_input_clear.py b/tests/input/test_input_clear.py
new file mode 100644
index 000000000..07abff1a7
--- /dev/null
+++ b/tests/input/test_input_clear.py
@@ -0,0 +1,16 @@
+from textual.app import App, ComposeResult
+from textual.widgets import Input
+
+
+class InputApp(App):
+    def compose(self) -> ComposeResult:
+        yield Input("Hello, World!")
+
+
+async def test_input_clear():
+    async with InputApp().run_test() as pilot:
+        input_widget = pilot.app.query_one(Input)
+        assert input_widget.value == "Hello, World!"
+        input_widget.clear()
+        await pilot.pause()
+        assert input_widget.value == ""