66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { Signal , WritableSignal , signal } from '@angular/core' ;
9+ import { WritableSignal , signal } from '@angular/core' ;
1010import { ListExpansion , ListExpansionInputs , ExpansionItem } from './expansion' ;
11- import { ListFocus , ListFocusInputs , ListFocusItem } from '../list-focus/list-focus' ;
12- import { getListFocus as getListFocusManager } from '../list-focus/list-focus.spec' ;
13-
14- type TestItem = ListFocusItem &
15- ExpansionItem & {
16- id : WritableSignal < string > ;
17- disabled : WritableSignal < boolean > ;
18- element : WritableSignal < HTMLElement > ;
19- expandable : WritableSignal < boolean > ;
20- expansionId : WritableSignal < string > ;
21- } ;
22-
23- type TestInputs = Partial < Omit < ListExpansionInputs < TestItem > , 'items' | 'focusManager' > > &
24- Partial <
25- Pick < ListFocusInputs < TestItem > , 'focusMode' | 'disabled' | 'activeIndex' | 'skipDisabled' >
26- > & {
27- numItems ?: number ;
28- initialExpandedIds ?: string [ ] ;
29- } ;
11+
12+ type TestItem = ExpansionItem & {
13+ id : WritableSignal < string > ;
14+ disabled : WritableSignal < boolean > ;
15+ expandable : WritableSignal < boolean > ;
16+ expansionId : WritableSignal < string > ;
17+ } ;
18+
19+ type TestInputs = Partial < Omit < ListExpansionInputs , 'items' > > & {
20+ numItems ?: number ;
21+ initialExpandedIds ?: string [ ] ;
22+ expansionDisabled ?: boolean ;
23+ } ;
3024
3125function createItems ( length : number ) : WritableSignal < TestItem [ ] > {
3226 return signal (
3327 Array . from ( { length} ) . map ( ( _ , i ) => {
3428 const itemId = `item-${ i } ` ;
3529 return {
3630 id : signal ( itemId ) ,
37- element : signal ( document . createElement ( 'div' ) as HTMLElement ) ,
3831 disabled : signal ( false ) ,
3932 expandable : signal ( true ) ,
4033 expansionId : signal ( itemId ) ,
@@ -44,39 +37,24 @@ function createItems(length: number): WritableSignal<TestItem[]> {
4437}
4538
4639function getExpansion ( inputs : TestInputs = { } ) : {
47- expansion : ListExpansion < TestItem > ;
40+ expansion : ListExpansion ;
4841 items : TestItem [ ] ;
49- focusManager : ListFocus < TestItem > ;
5042} {
5143 const numItems = inputs . numItems ?? 3 ;
5244 const items = createItems ( numItems ) ;
5345
54- const listFocusManagerInputs : Partial < ListFocusInputs < TestItem > > & { items : Signal < TestItem [ ] > } = {
55- items : items ,
56- activeIndex : inputs . activeIndex ?? signal ( 0 ) ,
57- disabled : inputs . disabled ?? signal ( false ) ,
58- skipDisabled : inputs . skipDisabled ?? signal ( true ) ,
59- focusMode : inputs . focusMode ?? signal ( 'roving' ) ,
60- } ;
61-
62- const focusManager = getListFocusManager ( listFocusManagerInputs as any ) as ListFocus < TestItem > ;
63-
64- const expansion = new ListExpansion < TestItem > ( {
46+ const expansion = new ListExpansion ( {
6547 items : items ,
66- activeIndex : focusManager . inputs . activeIndex ,
67- disabled : focusManager . inputs . disabled ,
68- skipDisabled : focusManager . inputs . skipDisabled ,
69- focusMode : focusManager . inputs . focusMode ,
70- multiExpandable : inputs . multiExpandable ?? signal ( false ) ,
71- expandedIds : signal ( [ ] ) ,
72- focusManager,
48+ disabled : signal ( inputs . expansionDisabled ?? false ) ,
49+ multiExpandable : signal ( inputs . multiExpandable ?.( ) ?? false ) ,
50+ expandedIds : signal < string [ ] > ( [ ] ) ,
7351 } ) ;
7452
7553 if ( inputs . initialExpandedIds ) {
7654 expansion . expandedIds . set ( inputs . initialExpandedIds ) ;
7755 }
7856
79- return { expansion, items : items ( ) , focusManager } ;
57+ return { expansion, items : items ( ) } ;
8058}
8159
8260describe ( 'Expansion' , ( ) => {
@@ -112,8 +90,8 @@ describe('Expansion', () => {
11290 expect ( expansion . expandedIds ( ) ) . toEqual ( [ ] ) ;
11391 } ) ;
11492
115- it ( 'should not open an item if it is not focusable ( disabled and skipDisabled is true) ' , ( ) => {
116- const { expansion, items} = getExpansion ( { skipDisabled : signal ( true ) } ) ;
93+ it ( 'should not open an item if it is disabled' , ( ) => {
94+ const { expansion, items} = getExpansion ( ) ;
11795 items [ 1 ] . disabled . set ( true ) ;
11896 expansion . open ( items [ 1 ] ) ;
11997 expect ( expansion . expandedIds ( ) ) . toEqual ( [ ] ) ;
@@ -134,11 +112,8 @@ describe('Expansion', () => {
134112 expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-0' ] ) ;
135113 } ) ;
136114
137- it ( 'should not close an item if it is not focusable (disabled and skipDisabled is true)' , ( ) => {
138- const { expansion, items} = getExpansion ( {
139- initialExpandedIds : [ 'item-0' ] ,
140- skipDisabled : signal ( true ) ,
141- } ) ;
115+ it ( 'should not close an item if it is disabled' , ( ) => {
116+ const { expansion, items} = getExpansion ( { initialExpandedIds : [ 'item-0' ] } ) ;
142117 items [ 0 ] . disabled . set ( true ) ;
143118 expansion . close ( items [ 0 ] ) ;
144119 expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-0' ] ) ;
@@ -181,7 +156,7 @@ describe('Expansion', () => {
181156 expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-0' , 'item-2' ] ) ;
182157 } ) ;
183158
184- it ( 'should not expand items that are not focusable ( disabled and skipDisabled is true) ' , ( ) => {
159+ it ( 'should not expand items that are disabled' , ( ) => {
185160 const { expansion, items} = getExpansion ( {
186161 numItems : 3 ,
187162 multiExpandable : signal ( true ) ,
@@ -222,9 +197,8 @@ describe('Expansion', () => {
222197 expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-1' ] ) ;
223198 } ) ;
224199
225- it ( 'should not close items that are not focusable ( disabled and skipDisabled is true) ' , ( ) => {
200+ it ( 'should not close items that are disabled' , ( ) => {
226201 const { expansion, items} = getExpansion ( {
227- skipDisabled : signal ( true ) ,
228202 multiExpandable : signal ( true ) ,
229203 initialExpandedIds : [ 'item-0' , 'item-1' , 'item-2' ] ,
230204 } ) ;
@@ -235,22 +209,21 @@ describe('Expansion', () => {
235209 } ) ;
236210
237211 describe ( '#isExpandable' , ( ) => {
238- it ( 'should return true if an item is focusable and expandable is true' , ( ) => {
212+ it ( 'should return true if an item is not disabled and expandable is true' , ( ) => {
239213 const { expansion, items} = getExpansion ( ) ;
240214 items [ 0 ] . expandable . set ( true ) ;
241215 items [ 0 ] . disabled . set ( false ) ;
242216 expect ( expansion . isExpandable ( items [ 0 ] ) ) . toBeTrue ( ) ;
243217 } ) ;
244218
245- it ( 'should return false if an item is disabled and skipDisabled is false ' , ( ) => {
246- const { expansion, items} = getExpansion ( { skipDisabled : signal ( false ) } ) ;
219+ it ( 'should return false if an item is disabled' , ( ) => {
220+ const { expansion, items} = getExpansion ( ) ;
247221 items [ 0 ] . disabled . set ( true ) ;
248222 expect ( expansion . isExpandable ( items [ 0 ] ) ) . toBeFalse ( ) ;
249223 } ) ;
250224
251- it ( 'should return false if an item is disabled and skipDisabled is true' , ( ) => {
252- const { expansion, items} = getExpansion ( { skipDisabled : signal ( true ) } ) ;
253- items [ 0 ] . disabled . set ( true ) ;
225+ it ( 'should return false if the expansion behavior is disabled' , ( ) => {
226+ const { expansion, items} = getExpansion ( { expansionDisabled : true } ) ;
254227 expect ( expansion . isExpandable ( items [ 0 ] ) ) . toBeFalse ( ) ;
255228 } ) ;
256229
0 commit comments