Content
Updated by Henriette Darge 3 days ago
The following is a follow up of [this comment](https://community.openproject.org/projects/design-system/work_packages/62993/activity#comment-1189150) of #62993
## Problem
> Imagine the following very simple TreeView:
>
> ```erb
> <%= render(Primer::OpenProject::TreeView.new) do |tree_view| %>
> <% tree_view.with_sub_tree(label: "src") do |sub_tree| %>
> <% sub_tree.with_leaf(label: "button.rb", select_variant: select_variant) %>
> <% sub_tree.with_leaf(label: "icon_button.rb") %>
>
> <% sub_tree.with_sub_tree(label: "sub-folder", expanded: true, select_variant: select_variant, select_strategy: select_strategy) do |sub_tree2| %>
> <% sub_tree2.with_leaf(label: "test.rb") %>
> <% sub_tree2.with_leaf(label: "blankslate.rb", current: true) %>
> <% end %>
> <% end %>
>
> <% tree_view.with_leaf(label: "action_menu.rb") %>
> <% end %>
> ```
>
> Please note, that the second sub\_tree has `expanded: true` while the surrounding sub\_tree has `expanded` not set. Now, this will render to:
>
> <img class="op-uc-image op-uc-image_inline" src="/api/v3/attachments/567537/content">
>
> So, I will not see the subtree that I wanted to be expanded, because the parent is not expanded. I (as a developer) would have to manage that manually by setting each parent tree to `expanded: true`.
# Solution
**As** a developer
**I want to** set the `expanded` attributes only once
**so that** I do not have to repeat that for every node in the hierachy
**Acceptance criteria**
* Whenever, I set the value `expanded: true` on a leave or a node, all of its parent are automatically set to `expanded: true` as well.
**Hint for QA**
* Can _\[Open\] Should that be tested here: [https://qa.openproject-edge.com/lookbook/inspect/primer/open\_project/tree\_view/auto\_expansion](https://qa.openproject-edge.com/lookbook/inspect/primer/open_project/tree_view/auto_expansion) overridaeble? So that I can set_ `_expanded: false_` _to any parent manually if I want to?_
## Problem
> Imagine the following very simple TreeView:
>
> ```erb
> <%= render(Primer::OpenProject::TreeView.new) do |tree_view| %>
> <% tree_view.with_sub_tree(label: "src") do |sub_tree| %>
> <% sub_tree.with_leaf(label: "button.rb", select_variant: select_variant) %>
> <% sub_tree.with_leaf(label: "icon_button.rb") %>
>
> <% sub_tree.with_sub_tree(label: "sub-folder", expanded: true, select_variant: select_variant, select_strategy: select_strategy) do |sub_tree2| %>
> <% sub_tree2.with_leaf(label: "test.rb") %>
> <% sub_tree2.with_leaf(label: "blankslate.rb", current: true) %>
> <% end %>
> <% end %>
>
> <% tree_view.with_leaf(label: "action_menu.rb") %>
> <% end %>
> ```
>
> Please note, that the second sub\_tree has `expanded: true` while the surrounding sub\_tree has `expanded` not set. Now, this will render to:
>
> <img class="op-uc-image op-uc-image_inline" src="/api/v3/attachments/567537/content">
>
> So, I will not see the subtree that I wanted to be expanded, because the parent is not expanded. I (as a developer) would have to manage that manually by setting each parent tree to `expanded: true`.
# Solution
**As** a developer
**I want to** set the `expanded` attributes only once
**so that** I do not have to repeat that for every node in the hierachy
**Acceptance criteria**
* Whenever, I set the value `expanded: true` on a leave or a node, all of its parent are automatically set to `expanded: true` as well.
**Hint for QA**