textbox-autoheight (#1009)

* textbox-autoheight
- add max-lines to textbox

* textbox-autoheight
- reformat

* textbox-autoheight
- add demo

* textbox-autoheight
- tweaks on scripts

* textbox-autoheight
- fix tests

* textbox-autoheight
- fix tests

* textbox-autoheight
- fix tests

* textbox-autoheight
- convert default max_height from 100 to 20

* textbox-autoheight
- convert default max_height from 100 to 20
This commit is contained in:
Ömer Faruk Özdemir 2022-04-20 14:25:47 +03:00 committed by GitHub
parent db481311a6
commit 9cd4c3121f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 9 deletions

View File

@ -0,0 +1,13 @@
import gradio as gr
def greet(name: str, repeat: int):
return "Hello " + name * repeat + "!!"
demo = gr.Interface(
fn=greet, inputs=[gr.Textbox(lines=2, max_lines=4), gr.Number()], outputs=gr.component("textarea")
)
if __name__ == "__main__":
demo.launch()

View File

@ -250,6 +250,7 @@ class Textbox(Component):
default_value: str = "",
*,
lines: int = 1,
max_lines: int = 20,
placeholder: Optional[str] = None,
label: Optional[str] = None,
css: Optional[Dict] = None,
@ -258,7 +259,8 @@ class Textbox(Component):
"""
Parameters:
default_value (str): default text to provide in textarea.
lines (int): number of line rows to provide in textarea.
lines (int): minimum number of line rows to provide in textarea.
max_lines (int): maximum number of line rows to provide in textarea.
placeholder (str): placeholder hint to provide behind textarea.
label (str): component name in interface.
"""
@ -274,6 +276,7 @@ class Textbox(Component):
)
default_value = str(default_value)
self.lines = lines
self.max_lines = max_lines
self.placeholder = placeholder
self.default_value = default_value
self.test_input = default_value
@ -283,6 +286,7 @@ class Textbox(Component):
def get_template_context(self):
return {
"lines": self.lines,
"max_lines": self.max_lines,
"placeholder": self.placeholder,
"default_value": self.default_value,
**super().get_template_context(),

View File

@ -124,6 +124,7 @@ XRAY_CONFIG = {
"type": "textbox",
"props": {
"lines": 1,
"max_lines": 20,
"placeholder": None,
"default_value": "",
"name": "textbox",
@ -318,6 +319,7 @@ XRAY_CONFIG_DIFF_IDS = {
"placeholder": None,
"default_value": "",
"name": "textbox",
"max_lines": 20,
"label": None,
"css": {},
"interactive": None,

View File

@ -1,8 +0,0 @@
#!/bin/bash
if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
echo "Please run the script from repo directory"
exit -1
else
echo "Running the tests"
python -m pytest --cov=gradio --durations=20 --durations-min=0.1 test/local
fi

View File

@ -85,6 +85,7 @@ class TestTextbox(unittest.TestCase):
text_input.get_template_context(),
{
"lines": 1,
"max_lines": 20,
"placeholder": None,
"default_value": "",
"name": "textbox",
@ -1466,6 +1467,7 @@ class TestCarousel(unittest.TestCase):
"label": None,
"default_value": "",
"lines": 1,
"max_lines": 20,
"css": {},
"placeholder": None,
"interactive": None,

View File

@ -439,6 +439,7 @@ class TestCarousel(unittest.TestCase):
"label": None,
"default_value": "",
"lines": 1,
"max_lines": 20,
"css": {},
"placeholder": None,
"interactive": None,