Skip to content

Commit cf7eae7

Browse files
committed
Update native_input -> native_textarea because it's more flexible
1 parent 7669746 commit cf7eae7

File tree

6 files changed

+28
-31
lines changed

6 files changed

+28
-31
lines changed

docs/components/input.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ For longer text inputs, also see [Textarea](./textarea.md)
1313
## API
1414

1515
::: mesop.components.input.input.input
16-
::: mesop.components.input.input.native_input
16+
::: mesop.components.input.input.native_textarea

mesop/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from mesop.components.icon.icon import icon as icon
5353
from mesop.components.image.image import image as image
5454
from mesop.components.input.input import input as input
55-
from mesop.components.input.input import native_input as native_input
55+
from mesop.components.input.input import native_textarea as native_textarea
5656
from mesop.components.input.input import textarea as textarea
5757
from mesop.components.markdown.markdown import markdown as markdown
5858
from mesop.components.plot.plot import (

mesop/components/input/e2e/input_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def app():
3636
),
3737
)
3838
):
39-
me.native_input(
39+
me.native_textarea(
4040
readonly=False,
4141
style=me.Style(
4242
height=32,

mesop/components/input/input.ng.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
@if(config().getIsNativeInput()) {
2-
<input
1+
@if(config().getIsNativeTextarea()) {
2+
<textarea
33
[disabled]="config().getDisabled()"
44
[placeholder]="config().getPlaceholder()!"
5-
[type]="config().getType()!"
65
[value]="config().getValue()"
76
[readonly]="config().getReadonly()"
87
[style]="getStyle()"
98
(input)="onInput($event)"
10-
/>
9+
[cdkTextareaAutosize]="config().getAutosize()"
10+
[cdkAutosizeMinRows]="config().getMinRows()"
11+
[cdkAutosizeMaxRows]="config().getMaxRows()"
12+
#autosize="cdkTextareaAutosize"
13+
></textarea>
1114
} @else {
1215
<mat-form-field
1316
[hideRequiredMarker]="config().getHideRequiredMarker()"

mesop/components/input/input.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ message InputType {
2727
optional int32 max_rows = 22;
2828
// Not exposed as public API.
2929
optional bool is_textarea = 19;
30-
optional bool is_native_input = 23;
30+
optional bool is_native_textarea = 23;
3131
}

mesop/components/input/input.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def textarea(
3737
3838
Args:
3939
label: Label for input.
40+
autosize: If True, the textarea will automatically adjust its height to fit the content, up to the max_rows limit.
41+
min_rows: The minimum number of rows the textarea will display.
42+
max_rows: The maximum number of rows the textarea will display.
4043
on_input: [input](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event) is a native browser event.
4144
rows: The number of lines to show in the text area.
4245
appearance: The form field appearance style.
@@ -63,7 +66,7 @@ def textarea(
6366
min_rows=min_rows,
6467
max_rows=max_rows,
6568
is_textarea=True,
66-
is_native_input=False,
69+
is_native_textarea=False,
6770
disabled=disabled,
6871
placeholder=placeholder,
6972
required=required,
@@ -145,7 +148,7 @@ def input(
145148
type_name="input",
146149
proto=input_pb.InputType(
147150
is_textarea=False,
148-
is_native_input=False,
151+
is_native_textarea=False,
149152
disabled=disabled,
150153
placeholder=placeholder,
151154
required=required,
@@ -167,37 +170,26 @@ def input(
167170
)
168171

169172

170-
def native_input(
173+
def native_textarea(
171174
*,
172175
on_input: Callable[[InputEvent], Any] | None = None,
173-
type: Literal[
174-
"color",
175-
"date",
176-
"datetime-local",
177-
"email",
178-
"month",
179-
"number",
180-
"password",
181-
"search",
182-
"tel",
183-
"text",
184-
"time",
185-
"url",
186-
"week",
187-
]
188-
| None = None,
176+
autosize: bool = False,
177+
min_rows: int | None = None,
178+
max_rows: int | None = None,
189179
style: Style | None = None,
190180
disabled: bool = False,
191181
placeholder: str = "",
192182
value: str = "",
193183
readonly: bool = False,
194184
key: str | None = None,
195185
):
196-
"""Creates a browser native Input component. Intended for advanced use cases with maximum UI control.
186+
"""Creates a browser native Textarea component. Intended for advanced use cases with maximum UI control.
197187
198188
Args:
199189
on_input: [input](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event) is a native browser event.
200-
type: Input type of the element. For textarea, use `me.Textarea(...)`
190+
autosize: If True, the textarea will automatically adjust its height to fit the content, up to the max_rows limit.
191+
min_rows: The minimum number of rows the textarea will display.
192+
max_rows: The maximum number of rows the textarea will display.
201193
style: Style for input.
202194
disabled: Whether it's disabled.
203195
placeholder: Placeholder value
@@ -211,10 +203,12 @@ def native_input(
211203
type_name="input",
212204
proto=input_pb.InputType(
213205
is_textarea=False,
214-
is_native_input=True,
206+
is_native_textarea=True,
207+
autosize=autosize,
208+
min_rows=min_rows,
209+
max_rows=max_rows,
215210
disabled=disabled,
216211
placeholder=placeholder,
217-
type=type,
218212
value=value,
219213
readonly=readonly,
220214
on_input_handler_id=register_event_handler(on_input, event=InputEvent)

0 commit comments

Comments
 (0)