Skip to content

Commit

Permalink
Merge pull request #1239 from zauberzeug/tree_expand
Browse files Browse the repository at this point in the history
add demo for tree expansion/collapse
  • Loading branch information
falkoschindler committed Jul 24, 2023
2 parents 9ca2a74 + 73ad441 commit c63d65b
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
Expand Up @@ -33,3 +33,24 @@ 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():
from typing import List

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('none', 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 c63d65b

Please sign in to comment.