angular / angular/components

CdkTree does not populate some CdkTreeNodeOutletContext properties

オープン
#12,034 コメント 3 件 リアクション 6 件 担当者 0 名 GitHub で見る
area: cdk/tree P4
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

#### Bug, feature request, or proposal:
Bug

#### What is the expected behavior?
`CdkTreeNodeOutletContext` has the following properties:
```ts
/** Depth of the node. */
level: number;

/** Index location of the node. */
index?: number;

/** Length of the number of total dataNodes. */
count?: number;
```
All of them should be populated when creating the context and before embedding the node ([see code reference](https://github.com/angular/material2/blob/c40fef4b1ab77593d21edee07fe1e68fa2459c94/src/cdk/tree/tree.ts#L253)).

#### What is the current behavior?
Only `level` is populated. `index` and `count` are not populated and cannot be used in the TreeNode's template to track the current position or total count. I assume that `index` should be the index of the node, relative to its siblings in its branch at the same level, and `count` should be the total number of siblings in the same branch at that level.

#### What are the steps to reproduce?
When using all three properties of the context, only `level` is populated - [see Stackblitz example](https://stackblitz.com/edit/angular-qa9gcr-w2c4w5?file=app/cdk-tree-nested-example.html)

#### What is the use-case or motivation for changing an existing behavior?
Developers should have access to the node's current position in their template, similarly to how they can track index in `ngFor`.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
All

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

src/cdk/tree/tree.ts の参照されている CdkTreeNodeOutletContext の作成箇所から始め、StackBlitz の再現例とその動作を比較します。ノードが埋め込まれる前にコンテキストが level、index、count を公開することを確認し、index と count がそのブランチレベルにおけるノードの位置と合計を表すようにします。再現例で 3 つの値を確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。