@@ -220,6 +220,69 @@ export class Tree<V> {
220220 scrollActiveItemIntoView ( options : ScrollIntoViewOptions = { block : 'nearest' } ) {
221221 this . _pattern . inputs . activeItem ( ) ?. element ( ) . scrollIntoView ( options ) ;
222222 }
223+
224+ /** Navigates to the first tree item. */
225+ first ( ) {
226+ this . _pattern . listBehavior . first ( { selectOne : this . followFocus ( ) } ) ;
227+ }
228+
229+ /** Navigates to the last tree item. */
230+ last ( ) {
231+ this . _pattern . listBehavior . last ( { selectOne : this . followFocus ( ) } ) ;
232+ }
233+
234+ /** Navigates to the previous tree item. */
235+ prev ( ) {
236+ this . _pattern . listBehavior . prev ( { selectOne : this . followFocus ( ) } ) ;
237+ }
238+
239+ /** Navigates to the next tree item. */
240+ next ( ) {
241+ this . _pattern . listBehavior . next ( { selectOne : this . followFocus ( ) } ) ;
242+ }
243+
244+ /** Opens the tree item with the specified value. */
245+ open ( itemValue : string ) {
246+ const item = this . _findItemPatternByValue ( itemValue ) ;
247+
248+ if ( item ) {
249+ this . _pattern . expansionManager . open ( item ) ;
250+ }
251+ }
252+
253+ /** Closes the tree itemwith the specified value. */
254+ close ( itemValue : string ) {
255+ const item = this . _findItemPatternByValue ( itemValue ) ;
256+
257+ if ( item ) {
258+ this . _pattern . expansionManager . close ( item ) ;
259+ }
260+ }
261+
262+ /** Toggles the expansion state of the tree item with the specified value. */
263+ toggle ( itemValue : string ) {
264+ const item = this . _findItemPatternByValue ( itemValue ) ;
265+
266+ if ( item ) {
267+ this . _pattern . expansionManager . toggle ( item ) ;
268+ }
269+ }
270+
271+ /** Opens all tree items if multi-expandable. */
272+ openAll ( ) {
273+ this . _pattern . expansionManager . openAll ( ) ;
274+ }
275+
276+ /** Closes all tree items. */
277+ closeAll ( ) {
278+ this . _pattern . expansionManager . closeAll ( ) ;
279+ }
280+
281+ _findItemPatternByValue ( value : string ) {
282+ const item = [ ...this . _unorderedItems ( ) ] . find ( i => i . value ( ) === value ) ;
283+
284+ return item ?. _pattern ;
285+ }
223286}
224287
225288/**
@@ -362,6 +425,21 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
362425 unregister ( ) {
363426 this . _group . set ( undefined ) ;
364427 }
428+
429+ /** Opens this item. */
430+ open ( itemValue : string ) {
431+ this . _pattern . expansion . open ( ) ;
432+ }
433+
434+ /** Closes this item. */
435+ close ( itemValue : string ) {
436+ this . _pattern . expansion . close ( ) ;
437+ }
438+
439+ /** Toggles the expansion state of this item. */
440+ toggle ( itemValue : string ) {
441+ this . _pattern . expansion . toggle ( ) ;
442+ }
365443}
366444
367445/**
0 commit comments