@@ -10,7 +10,12 @@ import {ComboboxInputs, ComboboxPattern} from './combobox';
1010import { OptionPattern } from '../listbox/option' ;
1111import { ComboboxListboxPattern } from '../listbox/combobox-listbox' ;
1212import { createKeyboardEvent } from '@angular/cdk/testing/private' ;
13- import { SignalLike , signal , WritableSignalLike } from '../behaviors/signal-like/signal-like' ;
13+ import {
14+ SignalLike ,
15+ signal ,
16+ WritableSignalLike ,
17+ computed ,
18+ } from '../behaviors/signal-like/signal-like' ;
1419import { ModifierKeys } from '@angular/cdk/testing' ;
1520import { TreeItemPattern } from '../tree/tree' ;
1621import { ComboboxTreePattern } from '../tree/combobox-tree' ;
@@ -78,7 +83,7 @@ function _type(
7883 if ( popup instanceof ComboboxListboxPattern ) {
7984 ( popup . inputs . items as WritableSignalLike < any [ ] > ) . set ( options ) ;
8085 } else if ( popup instanceof ComboboxTreePattern ) {
81- ( popup . inputs . allItems as WritableSignalLike < any [ ] > ) . set ( options ) ;
86+ ( popup . inputs . items as WritableSignalLike < any [ ] > ) . set ( options ) ;
8287 }
8388 firstMatch . set ( options [ 0 ] ?. value ( ) ) ;
8489 combobox . onFilter ( ) ;
@@ -164,7 +169,7 @@ function getTreePattern(
164169
165170 const tree = new ComboboxTreePattern < string > ( {
166171 id : signal ( 'tree-1' ) ,
167- allItems : items ,
172+ items,
168173 values : signal ( initialValue ? [ initialValue ] : [ ] ) ,
169174 combobox : signal ( combobox ) as any ,
170175 activeItem : signal ( undefined ) ,
@@ -182,6 +187,10 @@ function getTreePattern(
182187 currentType : signal ( 'false' ) ,
183188 } ) ;
184189
190+ class TestTreeItemPattern extends TreeItemPattern < string > {
191+ override readonly focusable = computed ( ( ) => this . inputs . focusable ?.( ) ?? true ) ;
192+ }
193+
185194 // Recursive function to create tree items
186195 function createTreeItems (
187196 data : TreeItemData [ ] ,
@@ -190,9 +199,9 @@ function getTreePattern(
190199 return data . map ( ( node , index ) => {
191200 const element = document . createElement ( 'div' ) ;
192201 element . role = 'treeitem' ;
193- const treeItem = new TreeItemPattern < string > ( {
202+ const treeItem = new TestTreeItemPattern ( {
194203 value : signal ( node . value ) ,
195- id : signal ( 'tree-item-' + tree . inputs . allItems ( ) . length ) ,
204+ id : signal ( 'tree-item-' + tree . inputs . items ( ) . length ) ,
196205 disabled : signal ( false ) ,
197206 selectable : signal ( true ) ,
198207 expanded : signal ( false ) ,
@@ -204,7 +213,7 @@ function getTreePattern(
204213 children : signal ( [ ] ) ,
205214 } ) ;
206215
207- ( tree . inputs . allItems as WritableSignalLike < TreeItemPattern < string > [ ] > ) . update ( items =>
216+ ( tree . inputs . items as WritableSignalLike < TreeItemPattern < string > [ ] > ) . update ( items =>
208217 items . concat ( treeItem ) ,
209218 ) ;
210219
@@ -686,11 +695,17 @@ describe('Combobox with Tree Pattern', () => {
686695
687696 it ( 'should expand a closed node on ArrowRight' , ( ) => {
688697 const { combobox, tree} = getPatterns ( ) ;
689- const before = tree . visibleItems ( ) . map ( i => i . searchTerm ( ) ) ;
698+ const before = tree . inputs
699+ . items ( )
700+ . filter ( i => i . visible ( ) )
701+ . map ( i => i . searchTerm ( ) ) ;
690702 expect ( before ) . toEqual ( [ 'Fruit' , 'Vegetables' , 'Grains' ] ) ;
691703 combobox . onKeydown ( down ( ) ) ;
692704 combobox . onKeydown ( right ( ) ) ;
693- const after = tree . visibleItems ( ) . map ( i => i . searchTerm ( ) ) ;
705+ const after = tree . inputs
706+ . items ( )
707+ . filter ( i => i . visible ( ) )
708+ . map ( i => i . searchTerm ( ) ) ;
694709 expect ( after ) . toEqual ( [ 'Fruit' , 'Apple' , 'Banana' , 'Cantaloupe' , 'Vegetables' , 'Grains' ] ) ;
695710 } ) ;
696711
@@ -707,7 +722,10 @@ describe('Combobox with Tree Pattern', () => {
707722 combobox . onKeydown ( down ( ) ) ;
708723 combobox . onKeydown ( right ( ) ) ;
709724 combobox . onKeydown ( left ( ) ) ;
710- const after = tree . visibleItems ( ) . map ( i => i . searchTerm ( ) ) ;
725+ const after = tree . inputs
726+ . items ( )
727+ . filter ( i => i . visible ( ) )
728+ . map ( i => i . searchTerm ( ) ) ;
711729 expect ( after ) . toEqual ( [ 'Fruit' , 'Vegetables' , 'Grains' ] ) ;
712730 expect ( tree . inputs . activeItem ( ) ?. searchTerm ( ) ) . toBe ( 'Fruit' ) ;
713731 } ) ;
@@ -756,15 +774,15 @@ describe('Combobox with Tree Pattern', () => {
756774 } ) ;
757775
758776 it ( 'should select and commit on click' , ( ) => {
759- combobox . onClick ( clickTreeItem ( tree . inputs . allItems ( ) , 0 ) ) ;
777+ combobox . onClick ( clickTreeItem ( tree . inputs . items ( ) , 0 ) ) ;
760778 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Fruit' ] ) ;
761779 expect ( inputEl . value ) . toBe ( 'Fruit' ) ;
762780 } ) ;
763781
764782 it ( 'should select and commit to input on Enter' , ( ) => {
765783 combobox . onKeydown ( down ( ) ) ;
766784 combobox . onKeydown ( enter ( ) ) ;
767- expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . allItems ( ) [ 0 ] ) ;
785+ expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . items ( ) [ 0 ] ) ;
768786 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Fruit' ] ) ;
769787 expect ( inputEl . value ) . toBe ( 'Fruit' ) ;
770788 } ) ;
@@ -816,8 +834,8 @@ describe('Combobox with Tree Pattern', () => {
816834 } ) ;
817835
818836 it ( 'should select and commit on click' , ( ) => {
819- combobox . onClick ( clickTreeItem ( tree . inputs . allItems ( ) , 2 ) ) ;
820- expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . allItems ( ) [ 2 ] ) ;
837+ combobox . onClick ( clickTreeItem ( tree . inputs . items ( ) , 2 ) ) ;
838+ expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . items ( ) [ 2 ] ) ;
821839 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Banana' ] ) ;
822840 expect ( inputEl . value ) . toBe ( 'Banana' ) ;
823841 } ) ;
@@ -833,7 +851,7 @@ describe('Combobox with Tree Pattern', () => {
833851
834852 it ( 'should select the first item on arrow down when collapsed' , ( ) => {
835853 combobox . onKeydown ( down ( ) ) ;
836- expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . allItems ( ) [ 0 ] ) ;
854+ expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . items ( ) [ 0 ] ) ;
837855 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Fruit' ] ) ;
838856 } ) ;
839857
@@ -873,8 +891,8 @@ describe('Combobox with Tree Pattern', () => {
873891 } ) ;
874892
875893 it ( 'should select and commit on click' , ( ) => {
876- combobox . onClick ( clickTreeItem ( tree . inputs . allItems ( ) , 2 ) ) ;
877- expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . allItems ( ) [ 2 ] ) ;
894+ combobox . onClick ( clickTreeItem ( tree . inputs . items ( ) , 2 ) ) ;
895+ expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . items ( ) [ 2 ] ) ;
878896 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Banana' ] ) ;
879897 expect ( inputEl . value ) . toBe ( 'Banana' ) ;
880898 } ) ;
@@ -890,7 +908,7 @@ describe('Combobox with Tree Pattern', () => {
890908
891909 it ( 'should select the first item on arrow down when collapsed' , ( ) => {
892910 combobox . onKeydown ( down ( ) ) ;
893- expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . allItems ( ) [ 0 ] ) ;
911+ expect ( tree . getSelectedItems ( ) [ 0 ] ) . toBe ( tree . inputs . items ( ) [ 0 ] ) ;
894912 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Fruit' ] ) ;
895913 } ) ;
896914
@@ -945,7 +963,7 @@ describe('Combobox with Tree Pattern', () => {
945963 const { combobox, tree, inputEl} = getPatterns ( { readonly : true } ) ;
946964 combobox . onClick ( clickInput ( inputEl ) ) ;
947965 expect ( combobox . expanded ( ) ) . toBe ( true ) ;
948- combobox . onClick ( clickTreeItem ( tree . inputs . allItems ( ) , 0 ) ) ;
966+ combobox . onClick ( clickTreeItem ( tree . inputs . items ( ) , 0 ) ) ;
949967 expect ( tree . inputs . values ( ) ) . toEqual ( [ 'Fruit' ] ) ;
950968 expect ( inputEl . value ) . toBe ( 'Fruit' ) ;
951969 expect ( combobox . expanded ( ) ) . toBe ( false ) ;
0 commit comments