Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Tree): control activeItemIds through expanded prop of items #2061

Merged
merged 22 commits into from
Nov 18, 2019

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Oct 24, 2019

User passing expanded prop to items will allow him to control the expanded state of these items. Renamed open to expanded.

Controlling the Tree's activeItemIds will have precedence over this individual control method.

Added also missing tests for Tree, subcomponents and behaviors. Added / edited test definitions for behavior tests.

@silviuaavram silviuaavram changed the title feat(Tree): control expended prop of items feat(Tree): control activeItemIds through expended prop of items Oct 25, 2019
@mnajdova
Copy link
Contributor

mnajdova commented Nov 8, 2019

Let's add an example of how the user can control the expended prop

@@ -117,7 +117,7 @@ class TreeItem extends UIComponent<WithAsProp<TreeItemProps>, TreeItemState> {
onFocusFirstChild: PropTypes.func,
onFocusParent: PropTypes.func,
onSiblingsExpand: PropTypes.func,
open: PropTypes.bool,
expanded: PropTypes.bool,
Copy link
Contributor

@mnajdova mnajdova Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be treated as auto controlled prop, by defining defaultExpanded and onExpandedChange. With this we will allow the user to define only the initial state, if they want that, or listen to the onExpandedChange and change the expanded prop by themselves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not having any state in TreeItem. All expanded stateful logic is in Tree, since TreeItems can be unmounted on virtualization. This is just a prop. The user can control it as it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this one. I understand that it is just a prop, but all other similar props are treated as autocontrolled. @miroslavstastny thoughts on this?

_.reduce(
items,
(acc, item) => {
if (item['expanded'] && acc.indexOf(item['id']) === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items could be defined as render functions too, we should handle that case, or at least check whether it is an object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it won't work well with render functions. We are calculating some props that we pass to TreeItem from Tree in getItemsForRender. However we probably can support this scenario with render prop as well. We just call the children function with the props from itemsForRender so the child component has access to them as well.

I would consider working on this in a separate PR. And just perform here the object check as per suggestion.

What do you think @mnajdova @jurokapsiar @miroslavstastny ?

@silviuaavram silviuaavram merged commit 3adb87d into master Nov 18, 2019
@silviuaavram silviuaavram deleted the feat/control-tree-expanded branch November 18, 2019 18:03
@silviuaavram silviuaavram changed the title feat(Tree): control activeItemIds through expended prop of items feat(Tree): control activeItemIds through expanded prop of items Nov 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants