Skip to content

Commit 1a89c3a

Browse files
committed
feat: add material title movement
- add material-like title movement on focus change for TextInput - add material-like title movement on focus change for IntegerInput - add example of title movement to simple_form
1 parent 81ef06d commit 1a89c3a

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

examples/simple_form.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ async def on_mount(self) -> None:
9090
)
9191
self.password = TextInput(
9292
name="password",
93-
placeholder="enter your password...",
9493
title="Password",
9594
password=True,
9695
)

src/textual_inputs/integer_input.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,28 @@ def render(self) -> RenderableType:
118118
segments = self._render_text_with_cursor()
119119
else:
120120
if len(value) == 0:
121-
segments = [self.placeholder]
121+
if self.title and not self.placeholder:
122+
segments = [self.title]
123+
else:
124+
segments = [self.placeholder]
122125
else:
123126
segments = [value]
124127

125128
text = Text.assemble(*segments)
126129

130+
if (
131+
self.title
132+
and not self.placeholder
133+
and self.value is None
134+
and not self.has_focus
135+
):
136+
title = ""
137+
else:
138+
title = self.title
139+
127140
return Panel(
128141
text,
129-
title=self.title,
142+
title=title,
130143
title_align="left",
131144
height=3,
132145
style=self.style or "",

src/textual_inputs/text_input.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,28 @@ def render(self) -> RenderableType:
110110
segments = self._render_text_with_cursor()
111111
else:
112112
if len(self.value) == 0:
113-
segments = [self.placeholder]
113+
if self.title and not self.placeholder:
114+
segments = [self.title]
115+
else:
116+
segments = [self.placeholder]
114117
else:
115118
segments = [self._conceal_or_reveal(self.value)]
116119

117120
text = Text.assemble(*segments)
118121

122+
if (
123+
self.title
124+
and not self.placeholder
125+
and len(self.value) == 0
126+
and not self.has_focus
127+
):
128+
title = ""
129+
else:
130+
title = self.title
131+
119132
return Panel(
120133
text,
121-
title=self.title,
134+
title=title,
122135
title_align="left",
123136
height=3,
124137
style=self.style or "",

0 commit comments

Comments
 (0)