Skip to content

Commit

Permalink
feat(input): add clear method
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Sep 29, 2023
1 parent dee7459 commit 46c409b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ def insert_text_at_cursor(self, text: str) -> None:
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
Expand Down
16 changes: 16 additions & 0 deletions tests/input/test_input_clear.py
Original file line number Diff line number Diff line change
@@ -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 == ""

0 comments on commit 46c409b

Please sign in to comment.