Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ui5-tree (new component) #1580

Merged
merged 30 commits into from
May 13, 2020
Merged

feat: ui5-tree (new component) #1580

merged 30 commits into from
May 13, 2020

Conversation

vladitasev
Copy link
Contributor

@vladitasev vladitasev commented May 5, 2020

ui5-tree:

  • is based on ui5-list, but does not extend it, composes it instead and proxies properties/slots/events to/from it.
  • uses ui5-tree-item as an abstract (no-renderer) item recursively
  • the ui5-list internally uses ui5-li-tree - a specific tree item, not intended for the end user, only for internal usage in the list of the tree
  • has specific visual design: only top-level nodes are of the default list item color, the other ones are of the alternative list color and have no borders. Also all items are not "actionable" in terms of design
  • has keyboard handling: left/right arrow drills down/up and collapses/expands
  • has accessibility: role=tree for the tree itself; role=treeitem, ariaExpanded bound to the expanded property, and ariaLevel bound to the level property for tree list items
  • has compact/cozy parameters for the arrow and toggle box. Indentation is done by padding, for IE there is a limitation: for both cozy and compact the padding is the same. Therefore, there are 2 padding styles, one for IE (the first), and one for other browsers (the second with calc)
  • The most important event itemToggle can be prevented by the user in order to fetch tree items dynamically, and then the toggling can be done manually with toggle() on the tree node.
  • Uses a Mutation Observer on itself, the items don't have managedSlots: true so they never know if they change and they never invalidate the tree directly.
  • The list items and tree items are linked via _ids so that lithtml can insert/delete, rather than overwrite list items, when tree items are modified.

Additionally, fixed some findings in related files:

  • List.js small doc fixes
  • ListItem.css invalid host selector :host() instead of just :host
  • sizes-parameters.css many duplicated vars deleted

closes: #1550

@vladitasev vladitasev changed the title PoC: ui5-tree feat: ui5-tree (new component) May 8, 2020
Copy link
Member

@ilhan007 ilhan007 left a comment

Choose a reason for hiding this comment

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

The code look good to me, it would be good to have few tests

Copy link
Member

@ilhan007 ilhan007 left a comment

Choose a reason for hiding this comment

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

There is sth minor that can be implemented later, but just to mention it, the user cant drill up and down the nodes with ARROW-RIGHT|LEFT keys.

Copy link
Member

@ilhan007 ilhan007 left a comment

Choose a reason for hiding this comment

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

also we will need a sample.html for the playground

* @alias sap.ui.webcomponents.main.Tree
* @extends UI5Element
* @tagname ui5-tree
* @appenddocs TreeItem
Copy link
Member

Choose a reason for hiding this comment

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

add since

* @constructor
* @author SAP SE
* @alias sap.ui.webcomponents.main.TreeItem
* @extends UI5Element
Copy link
Member

Choose a reason for hiding this comment

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

add since

@@ -0,0 +1,188 @@
<header>
Copy link
Member

Choose a reason for hiding this comment

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

To display since there is special marker:

<header class="component-heading">
	<h2 class="control-header">Tree</h2>
	<div class="component-heading-since">
		<span><!--since_tag_marker--></span>
	</div>
</header>

<script>
var dynamicTree = document.getElementById("treeDynamic");
dynamicTree.addEventListener("itemToggle", function(event) {
const item = event.detail.item; // get the node that is toggled
Copy link
Member

Choose a reason for hiding this comment

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

There are some "const" in the Tree.html and Tree.sample.html, maybe we should replace them with vars.

ilhan007
ilhan007 previously approved these changes May 12, 2020
ilhan007
ilhan007 previously approved these changes May 13, 2020
packages/main/src/Tree.js Outdated Show resolved Hide resolved
packages/main/src/Tree.js Outdated Show resolved Hide resolved
/**
* Defines the <code>ui5-tree</code> header.
* <br><br>
* <b>Note:</b> When <code>header</code> is set, the
Copy link
Contributor

Choose a reason for hiding this comment

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

header slot is set..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

onEnterDOM() {
this._observer = new MutationObserver(this.onTreeStructureChange.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can check if the _observer is available and not create multiple observers if the tree is added and removed from the DOM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, moved to constructor

}

get list() {
return this.shadowRoot.querySelector(`ui5-list`);
Copy link
Contributor

Choose a reason for hiding this comment

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

this.getDomRef.querySelector()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, when I removed the busy indicator, this.getDomRef() is the list (top-level element) but I kept the getter for semantics

}
}

const walkTree = (el, level, callback) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered walkTree & buildTree to be static methods in the Tree class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought about it, but I prefer them hidden for the moment

@vladitasev vladitasev merged commit 2dd97cf into master May 13, 2020
@vladitasev vladitasev deleted the ui5-tree branch May 13, 2020 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui5-tree: new component
3 participants