Explorar o código

#272 add demo and test

Falko Schindler %!s(int64=2) %!d(string=hai) anos
pai
achega
4cbf77f591
Modificáronse 2 ficheiros con 54 adicións e 0 borrados
  1. 33 0
      tests/test_select.py
  2. 21 0
      website/more_documentation/select_documentation.py

+ 33 - 0
tests/test_select.py

@@ -0,0 +1,33 @@
+from nicegui import ui
+
+from .screen import Screen
+
+
+def test_select(screen: Screen):
+    ui.select(['A', 'B', 'C'], value='A')
+
+    screen.open('/')
+    screen.should_contain('A')
+    screen.should_not_contain('B')
+    screen.should_not_contain('C')
+
+    screen.click('A')  # open the dropdown
+    screen.click('B')  # close the dropdown
+    screen.wait(0.5)
+    screen.should_not_contain('A')
+    screen.should_contain('B')
+    screen.should_not_contain('C')
+
+
+def test_select_with_input(screen: Screen):
+    ui.select(['A', 'AB', 'XYZ'], with_input=True)
+
+    screen.open('/')
+    screen.find_by_tag('input').click()
+    screen.should_contain('XYZ')
+
+    screen.find_by_tag('input').send_keys('A')
+    screen.wait(0.5)
+    screen.should_contain('A')
+    screen.should_contain('AB')
+    screen.should_not_contain('XYZ')

+ 21 - 0
website/more_documentation/select_documentation.py

@@ -1,6 +1,27 @@
 from nicegui import ui
 
+from ..documentation_tools import text_demo
+
 
 def main_demo() -> None:
     select1 = ui.select([1, 2, 3], value=1)
     select2 = ui.select({1: 'One', 2: 'Two', 3: 'Three'}).bind_value(select1, 'value')
+
+
+def more() -> None:
+    @text_demo('Search-as-you-type', '''
+        You can activate `with_input` to get a text input with autocompletion.
+        The options will be filtered as you type.
+    ''')
+    def search_as_you_type():
+        continents = [
+            'Asia',
+            'Africa',
+            'Antarctica',
+            'Europe',
+            'Oceania',
+            'North America',
+            'South America',
+        ]
+        ui.select(options=continents, with_input=True,
+                  on_change=lambda e: ui.notify(e.value)).classes('w-40')