From e48880a29ed0b2e4fce889391754950b2bee18fd Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 6 Jul 2026 10:11:30 +0200 Subject: [PATCH] :sparkles: Add more parameters to the ModalInput --- ChangeLog.md | 7 ++++++ src/textual_enhanced/__main__.py | 5 +++- src/textual_enhanced/dialogs/modal_input.py | 28 ++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 40771df..cb4d522 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,12 @@ # textual-enhanced ChangeLog +## Unreleased + +**Released: WiP** + +- Added `password`, `suggester`, `title` and `sub_title` to `ModalInput`. + ([#76](https://github.com/davep/textual-enhanced/pull/76)) + ## v1.5.0 **Released: 2026-05-22** diff --git a/src/textual_enhanced/__main__.py b/src/textual_enhanced/__main__.py index 819549d..e807506 100644 --- a/src/textual_enhanced/__main__.py +++ b/src/textual_enhanced/__main__.py @@ -127,7 +127,10 @@ async def input_action(self, message: Button.Pressed) -> None: ModalInput(placeholder="Enter some text here") if message.button.id == "input" else ModalInput( - placeholder="This has an initial value", initial="Testing..." + placeholder="This has an initial value", + initial="Testing...", + title="This is a title", + sub_title="This is a subtitle", ) ): self.notify(f"Entered '{text}") diff --git a/src/textual_enhanced/dialogs/modal_input.py b/src/textual_enhanced/dialogs/modal_input.py index 6fda0ad..f3dadc1 100644 --- a/src/textual_enhanced/dialogs/modal_input.py +++ b/src/textual_enhanced/dialogs/modal_input.py @@ -5,6 +5,7 @@ from textual import on from textual.app import ComposeResult from textual.screen import ModalScreen +from textual.suggester import Suggester from textual.widgets import Input @@ -32,6 +33,10 @@ def __init__( placeholder: str | None = None, initial: str = "", classes: str | None = None, + password: bool = False, + suggester: Suggester | None = None, + title: str | None = None, + sub_title: str | None = None, ) -> None: """Initialise the object. @@ -39,16 +44,37 @@ def __init__( placeholder: The placeholder text to use. initial: The initial value for the input. classes: The CSS classes of the modal input. + password: Whether the input is a password input. + suggester: The suggester to use for the input. + title: The title of the modal input. + sub_title: The subtitle of the modal input. """ super().__init__(classes=classes) self._placeholder = placeholder or "" """The placeholder to use for the input.""" self._initial = initial """The initial value for the input.""" + self._password = password + """Whether the input is a password input.""" + self._suggester = suggester + """The suggester to use for the input.""" + self._title = title + """The title of the modal input.""" + self._subtitle = sub_title + """The subtitle of the modal input.""" def compose(self) -> ComposeResult: """Compose the input dialog.""" - yield Input(self._initial, placeholder=self._placeholder) + yield ( + control := Input( + self._initial, + placeholder=self._placeholder, + suggester=self._suggester, + password=self._password, + ) + ) + control.border_title = self._title + control.border_subtitle = self._subtitle @on(Input.Submitted) def accept_input(self) -> None: