@@ -218,13 +218,12 @@ export class Tree<V> {
218218 '[attr.aria-current]' : 'pattern.current()' ,
219219 '[attr.aria-disabled]' : 'pattern.disabled()' ,
220220 '[attr.aria-level]' : 'pattern.level()' ,
221- '[attr.aria-owns]' : 'ownsId()' ,
222221 '[attr.aria-setsize]' : 'pattern.setsize()' ,
223222 '[attr.aria-posinset]' : 'pattern.posinset()' ,
224223 '[attr.tabindex]' : 'pattern.tabindex()' ,
225224 } ,
226225} )
227- export class TreeItem < V > implements OnInit , OnDestroy , HasElement {
226+ export class TreeItem < V > extends DeferredContentAware implements OnInit , OnDestroy , HasElement {
228227 /** A reference to the tree item element. */
229228 private readonly _elementRef = inject ( ElementRef ) ;
230229
@@ -234,9 +233,6 @@ export class TreeItem<V> implements OnInit, OnDestroy, HasElement {
234233 /** The owned tree item group. */
235234 private readonly _group = signal < TreeItemGroup < V > | undefined > ( undefined ) ;
236235
237- /** The id of the owned group. */
238- readonly ownsId = computed ( ( ) => this . _group ( ) ?. id ) ;
239-
240236 /** The host native element. */
241237 readonly element = computed ( ( ) => this . _elementRef . nativeElement ) ;
242238
@@ -267,9 +263,13 @@ export class TreeItem<V> implements OnInit, OnDestroy, HasElement {
267263 pattern : TreeItemPattern < V > ;
268264
269265 constructor ( ) {
270- // Updates the visibility of the owned group.
266+ super ( ) ;
267+ this . preserveContent . set ( true ) ;
268+ // Connect the group's hidden state to the DeferredContentAware's visibility.
271269 afterRenderEffect ( ( ) => {
272- this . _group ( ) ?. visible . set ( this . pattern . expanded ( ) ) ;
270+ this . tree ( ) . pattern instanceof ComboboxTreePattern
271+ ? this . contentVisible . set ( true )
272+ : this . contentVisible . set ( this . pattern . expanded ( ) ) ;
273273 } ) ;
274274 }
275275
@@ -289,12 +289,7 @@ export class TreeItem<V> implements OnInit, OnDestroy, HasElement {
289289 id : ( ) => this . _id ,
290290 tree : treePattern ,
291291 parent : parentPattern ,
292- children : computed (
293- ( ) =>
294- this . _group ( )
295- ?. children ( )
296- . map ( item => ( item as TreeItem < V > ) . pattern ) ?? [ ] ,
297- ) ,
292+ children : computed ( ( ) => this . _group ( ) ?. children ( ) ?? [ ] ) ,
298293 hasChildren : computed ( ( ) => ! ! this . _group ( ) ) ,
299294 } ) ;
300295 }
@@ -314,60 +309,30 @@ export class TreeItem<V> implements OnInit, OnDestroy, HasElement {
314309}
315310
316311/**
317- * Container that designates content as a group .
312+ * Contains children tree itmes .
318313 */
319314@Directive ( {
320- selector : '[ngTreeItemGroup]' ,
315+ selector : 'ng-template [ngTreeItemGroup]' ,
321316 exportAs : 'ngTreeItemGroup' ,
322- hostDirectives : [
323- {
324- directive : DeferredContentAware ,
325- inputs : [ 'preserveContent' ] ,
326- } ,
327- ] ,
328- host : {
329- 'class' : 'ng-treeitem-group' ,
330- 'role' : 'group' ,
331- '[id]' : 'id' ,
332- '[attr.inert]' : 'visible() ? null : true' ,
333- } ,
317+ hostDirectives : [ DeferredContent ] ,
334318} )
335- export class TreeItemGroup < V > implements OnInit , OnDestroy , HasElement {
336- /** A reference to the group element. */
337- private readonly _elementRef = inject ( ElementRef ) ;
338-
339- /** The DeferredContentAware host directive. */
340- private readonly _deferredContentAware = inject ( DeferredContentAware ) ;
319+ export class TreeItemGroup < V > implements OnInit , OnDestroy {
320+ /** The DeferredContent host directive. */
321+ private readonly _deferredContent = inject ( DeferredContent ) ;
341322
342323 /** All groupable items that are descendants of the group. */
343324 private readonly _unorderedItems = signal ( new Set < TreeItem < V > > ( ) ) ;
344325
345- /** The host native element. */
346- readonly element = computed ( ( ) => this . _elementRef . nativeElement ) ;
347-
348- /** Unique ID for the group. */
349- readonly id = inject ( _IdGenerator ) . getId ( 'ng-tree-group-' ) ;
350-
351- /** Whether the group is visible. */
352- readonly visible = signal ( true ) ;
353-
354326 /** Child items within this group. */
355- readonly children = computed ( ( ) => [ ...this . _unorderedItems ( ) ] . sort ( sortDirectives ) ) ;
327+ readonly children = computed < TreeItemPattern < V > [ ] > ( ( ) =>
328+ [ ...this . _unorderedItems ( ) ] . sort ( sortDirectives ) . map ( c => c . pattern ) ,
329+ ) ;
356330
357331 /** Tree item that owns the group. */
358332 readonly ownedBy = input . required < TreeItem < V > > ( ) ;
359333
360- constructor ( ) {
361- this . _deferredContentAware . preserveContent . set ( true ) ;
362- // Connect the group's hidden state to the DeferredContentAware's visibility.
363- afterRenderEffect ( ( ) => {
364- this . ownedBy ( ) . tree ( ) . pattern instanceof ComboboxTreePattern
365- ? this . _deferredContentAware . contentVisible . set ( true )
366- : this . _deferredContentAware . contentVisible . set ( this . visible ( ) ) ;
367- } ) ;
368- }
369-
370334 ngOnInit ( ) {
335+ this . _deferredContent . deferredContentAware . set ( this . ownedBy ( ) ) ;
371336 this . ownedBy ( ) . register ( this ) ;
372337 }
373338
@@ -385,13 +350,3 @@ export class TreeItemGroup<V> implements OnInit, OnDestroy, HasElement {
385350 this . _unorderedItems . set ( new Set ( this . _unorderedItems ( ) ) ) ;
386351 }
387352}
388-
389- /**
390- * A structural directive that marks the `ng-template` to be used as the content
391- * for a `TreeItemGroup`. This content can be lazily loaded.
392- */
393- @Directive ( {
394- selector : 'ng-template[ngTreeItemGroupContent]' ,
395- hostDirectives : [ DeferredContent ] ,
396- } )
397- export class TreeItemGroupContent { }
0 commit comments