-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(tree): Add material styled tree #8458
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
Conversation
@@ -6,7 +6,7 @@ | |||
* found in the LICENSE file at https://angular.io/license | |||
*/ | |||
import {Observable} from 'rxjs/Observable'; | |||
import {first} from 'rxjs/operators'; | |||
import {first} from 'rxjs/operators/first'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#8352
according to this PR "take(1)" may be better than "first" operator
import {BehaviorSubject} from 'rxjs/BehaviorSubject'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import {combineLatest} from 'rxjs/observable/combineLatest'; | ||
import {map} from 'rxjs/operators'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add /map
?
bfcc824
to
3da64a9
Compare
3da64a9
to
841b589
Compare
@tinayuangao rebase? |
looks like it has been rebased onto |
841b589
to
ba4ddb2
Compare
Rebased. Please take a look. Thanks! |
Could you add a material tree demo to the demo app? It's kind of hard to reason about the CSS without being able to see a demo |
@@ -214,7 +214,9 @@ export class CdkTree<T> implements CollectionViewer, OnInit, OnDestroy { | |||
// Set the data to just created `CdkTreeNode`. | |||
// The `CdkTreeNode` created from `createEmbeddedView` will be saved in static variable | |||
// `mostRecentTreeNode`. We get it from static variable and pass the node data to it. | |||
CdkTreeNode.mostRecentTreeNode.data = nodeData; | |||
if (CdkTreeNode.mostRecentTreeNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under what circumstances would this be undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to initialize mostRecentTreeNode
because of the error /usr/local/google/home/tinagao/WebstormProjects/material2/src/cdk/tree/node.ts:79:10: Metadata collected contains an error that will be reported at runtime: Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler.
So I initialize the static variable to be null, and we have to check whether it's null here.
But the value shouldn't be null
or undefined
when we call it from tree.ts
src/lib/tree/node.ts
Outdated
import {MatTreeNodeOutlet} from './outlet'; | ||
|
||
|
||
/** Workaround for https://github.com/angular/angular/issues/17849 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That issue is closed- is this still necessary? If so we should file a new issue.
host: { | ||
'[attr.role]': 'role', | ||
'class': 'mat-tree-node', | ||
'tabindex': '0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add TODO
for applying mixinTabIndex
?
src/lib/tree/outlet.ts
Outdated
@Directive({ | ||
selector: '[matTreeNodeOutlet]' | ||
}) | ||
export class MatTreeNodeOutlet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add here implements CdkTreeNodeOutlet
to make sure they stay the same API
src/lib/tree/tree-module.ts
Outdated
import {MatTreeNodeOutlet} from './outlet'; | ||
import {MatTreeNodePadding} from './padding'; | ||
|
||
const EXPORTED_DECLARATIONS = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAT_TREE_DIRECTIVES
?
ba4ddb2
to
911009f
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
src/lib/tree/tree.md
Outdated
|
||
### TreeControl | ||
|
||
The `TreeControl` expand/collapse of the tree node. Users can expand/collapse a tree node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first sentence sounds like it's missing something.
The `TreeControl` controls the expand/collapse state of tree nodes.
After that, it would be good to explain the two types of TreeControl
and when they'd be used before going into further detail
src/lib/tree/tree.md
Outdated
|
||
The trigger can be placed anywhere in the tree node, and is only triggered by `click` action. | ||
|
||
The trigger is also work with both flat tree and nested tree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can omit this last sentence about the trigger; if we don't say anything, the default would be that it can be used in either.
|
||
This tree builds on the foundation of the CDK tree and uses a similar interface for its | ||
data source input and template, except that its element and attribute selectors will be prefixed | ||
with `mat-` instead of `cdk-`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan on adding examples in a follow-up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I can add placeholders
src/lib/tree/tree.md
Outdated
`aria-labelledby`. The `aria-readonly` defaults to `true` if it's not set. | ||
|
||
Tree's role is `tree`. | ||
Node's default role is `treeitem`, and it will be changed to `group` if it has descendant nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would phrase this as
Parent nodes are given `role="group"`, while leaf nodes are given `role="treeitem"`
src/lib/tree/tree.md
Outdated
|
||
### Padding | ||
|
||
The `matTreeNodePadding` can be placed in a flat tree's node template to display the `level` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd more strongly emphasize that this is only for flat variations
The `mat-tree` provides a Material Design styled tree that can be used to display hierarchy | ||
data. | ||
|
||
This tree builds on the foundation of the CDK tree and uses a similar interface for its |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would mention the concept of flat vs. nested trees here, as early as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added flat tree and nested tree part. Please take a look. Thanks!
1553441
to
37c159f
Compare
src/lib/tree/tree.md
Outdated
two types of trees. | ||
|
||
#### Flat tree | ||
Flat tree has a list of flattened tree nodes. The hierarchy are flattened and no tree node is placed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a flat tree, the hierarchy is flattened; nodes are not rendered inside of each other,
but instead are rendered as siblings in sequence. An instance of `TreeFlattener` is
used to generate the flat list of items from hierarchical data. The "level" of each tree
node is read through the `getLevel` method of the `TreeControl`; this level can be
used to style the node such that it is indented to the appropriate level.
Is that accurate?
src/lib/tree/tree.md
Outdated
<mat-tree-node> -- child node2 </mat-tree-node> | ||
</mat-tree> | ||
``` | ||
A flat tree is easier to implement virtual scrolling in the future or render only part of the tree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flat trees are generally easier to style and inspect. They are also more friendly to
scrolling variations, such as infinite or virtual scrolling
src/lib/tree/tree.md
Outdated
</mat-tree> | ||
``` | ||
|
||
A nested tree is easier to decorate to show hierarchy information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
Nested trees are easier to work with when hierarchical relationships are visually
represented in ways that would be difficult to accomplish with flat nodes.
?
src/lib/tree/tree.md
Outdated
### Simple Tree | ||
|
||
In the near future, we will provide a simplified version of the tree with an easy-to-use | ||
interface, material styling, and json input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave out this section; I want to avoid talking about future stuff in the docs
37c159f
to
46f3274
Compare
Updated the document. Please take a look. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Demo: https://mat-tree-tina-demo.firebaseapp.com/tree