Skip to content

Commit

Permalink
add demo for tree expansion/collapse
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Jul 24, 2023
1 parent c48fae4 commit 09cfa00
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions website/more_documentation/tree_documentation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from nicegui import ui

from ..documentation_tools import text_demo
Expand Down Expand Up @@ -33,3 +35,22 @@ def tree_with_custom_header_and_body():
tree.add_slot('default-body', '''
<span :props="props">Description: "{{ props.node.description }}"</span>
''')

@text_demo('Expand programmatically', '''
The tree can be expanded programmatically by modifying the `expanded` prop.
''')
def expand_programmatically():
def expand(node_ids: List[str]) -> None:
t._props['expanded'] = node_ids
t.update()

with ui.row():
ui.button('all', on_click=lambda: expand(['A', 'B']))
ui.button('A', on_click=lambda: expand(['A']))
ui.button('B', on_click=lambda: expand(['B']))
ui.button('close', on_click=lambda: expand([]))

t = ui.tree([
{'id': 'A', 'children': [{'id': 'A1'}, {'id': 'A2'}]},
{'id': 'B', 'children': [{'id': 'B1'}, {'id': 'B2'}]},
], label_key='id')

0 comments on commit 09cfa00

Please sign in to comment.