Skip to content

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

Merged
merged 1 commit into from
Nov 28, 2017
Merged

Conversation

tinayuangao
Copy link
Contributor

@tinayuangao tinayuangao commented Nov 15, 2017

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 15, 2017
@@ -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';
Copy link

@TishchenkoAlex TishchenkoAlex Nov 15, 2017

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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Add /map?

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Nov 16, 2017
@jelbourn
Copy link
Member

@tinayuangao rebase?

@benb7760
Copy link

looks like it has been rebased onto master instead of onto tree

@tinayuangao
Copy link
Contributor Author

Rebased. Please take a look. Thanks!

@mmalerba mmalerba added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Nov 20, 2017
@mmalerba
Copy link
Contributor

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

@angular angular deleted a comment from googlebot Nov 21, 2017
@@ -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) {
Copy link
Member

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?

Copy link
Contributor Author

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

import {MatTreeNodeOutlet} from './outlet';


/** Workaround for https://github.com/angular/angular/issues/17849 */
Copy link
Member

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',
Copy link
Member

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?

@Directive({
selector: '[matTreeNodeOutlet]'
})
export class MatTreeNodeOutlet {
Copy link
Member

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

import {MatTreeNodeOutlet} from './outlet';
import {MatTreeNodePadding} from './padding';

const EXPORTED_DECLARATIONS = [
Copy link
Member

Choose a reason for hiding this comment

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

MAT_TREE_DIRECTIVES?

@googlebot
Copy link

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 cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Nov 21, 2017

### TreeControl

The `TreeControl` expand/collapse of the tree node. Users can expand/collapse a tree node
Copy link
Member

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


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.
Copy link
Member

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-`.
Copy link
Member

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?

Copy link
Contributor Author

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

`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.
Copy link
Member

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"`


### Padding

The `matTreeNodePadding` can be placed in a flat tree's node template to display the `level`
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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!

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
Copy link
Member

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?

<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.
Copy link
Member

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

</mat-tree>
```

A nested tree is easier to decorate to show hierarchy information.
Copy link
Member

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.

?

### 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.
Copy link
Member

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

@tinayuangao
Copy link
Contributor Author

Updated the document. Please take a look. Thanks!

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added cla: yes PR author has agreed to Google's Contributor License Agreement action: merge The PR is ready for merge by the caretaker pr: lgtm and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla pr: needs review labels Nov 28, 2017
@tinayuangao tinayuangao merged commit a6b63b2 into angular:tree Nov 28, 2017
tinayuangao added a commit that referenced this pull request Nov 29, 2017
tinayuangao added a commit that referenced this pull request Dec 9, 2017
tinayuangao added a commit that referenced this pull request Dec 13, 2017
tinayuangao added a commit that referenced this pull request Dec 14, 2017
tinayuangao added a commit that referenced this pull request Dec 15, 2017
tinayuangao added a commit to tinayuangao/material2 that referenced this pull request Dec 15, 2017
tinayuangao added a commit that referenced this pull request Dec 19, 2017
tinayuangao added a commit that referenced this pull request Jan 4, 2018
tinayuangao added a commit that referenced this pull request Jan 10, 2018
tinayuangao added a commit that referenced this pull request Jan 23, 2018
tinayuangao added a commit that referenced this pull request Feb 5, 2018
tinayuangao added a commit that referenced this pull request Feb 9, 2018
jelbourn pushed a commit that referenced this pull request Feb 12, 2018
tinayuangao added a commit that referenced this pull request Feb 13, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants