Skip to content

Commit

Permalink
fix(cdk/tree): change inputs back to regular @input
Browse files Browse the repository at this point in the history
  • Loading branch information
BobobUnicorn committed Nov 7, 2024
1 parent 4ff7dcb commit 1faed45
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/cdk/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,28 @@ export class CdkTree<T, K = T>
* relative to the function to know if a node should be added/removed/moved.
* Accepts a function that takes two parameters, `index` and `item`.
*/
readonly trackBy = input<TrackByFunction<T>>();
@Input()
set trackBy(trackBy: TrackByFunction<T>) {
this._trackBy.set(trackBy);
}
get trackBy(): TrackByFunction<T>|undefined {
return this._trackBy();
}

/**
* Given a data node, determines the key by which we determine whether or not this node is expanded.
*/
readonly expansionKey = input<(dataNode: T) => K>();
@Input()
set expansionKey(expansionKey: (dataNode: T) => K) {
this._expansionKey.set(expansionKey);
}
get expansionKey(): ((dataNode: T) => K)|undefined {
return this._expansionKey();
}

private readonly _trackBy = signal<TrackByFunction<T>|undefined>(undefined);

private readonly _expansionKey = signal<((dataNode: T) => K)|undefined>(undefined);

// Outlets within the tree's template where the dataNodes will be inserted.
@ViewChild(CdkTreeNodeOutlet, {static: true}) _nodeOutlet: CdkTreeNodeOutlet;
Expand Down Expand Up @@ -356,10 +372,10 @@ export class CdkTree<T, K = T>
// - if an expansionKey is provided, TS will infer the type of K to be
// the return type.
// - if it's not, then K will be defaulted to T.
return this.expansionKey() ?? ((item: T) => item as unknown as K);
return this._expansionKey() ?? ((item: T) => item as unknown as K);
});
readonly _trackByFn = computed(() => {
const trackBy = this.trackBy();
const trackBy = this._trackBy();
if (trackBy) return trackBy;
const expansionKey = this._expansionKeyFn();
// Provide a default trackBy based on `_ExpansionKey` if one isn't provided.
Expand Down

0 comments on commit 1faed45

Please sign in to comment.