Skip to content

Commit 85dceb0

Browse files
committed
fix(cdk-experimental/listbox): clean up the listbox API and make it work with forms
1 parent 4ba4755 commit 85dceb0

File tree

6 files changed

+434
-395
lines changed

6 files changed

+434
-395
lines changed

src/cdk-experimental/listbox/listbox.spec.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ComponentFixture, fakeAsync, TestBed, tick, waitForAsync} from '@angular/core/testing';
22
import {Component, DebugElement, ViewChild} from '@angular/core';
33
import {By} from '@angular/platform-browser';
4-
import {CdkListbox, CdkListboxModule, CdkOption, ListboxSelectionChangeEvent} from './index';
4+
import {CdkListbox, CdkListboxModule, CdkOption, ListboxValueChangeEvent} from './index';
55
import {
66
createKeyboardEvent,
77
dispatchKeyboardEvent,
@@ -114,17 +114,17 @@ describe('CdkOption and CdkListbox', () => {
114114
listboxInstance.setActiveOption(optionInstances[1]);
115115
fixture.detectChanges();
116116

117-
expect(listboxInstance._listKeyManager.activeItem).toBe(optionInstances[1]);
117+
expect(listboxInstance.listKeyManager.activeItem).toBe(optionInstances[1]);
118118

119119
dispatchKeyboardEvent(listboxElement, 'keydown', HOME);
120120
fixture.detectChanges();
121121

122-
expect(listboxInstance._listKeyManager.activeItem).toBe(optionInstances[0]);
122+
expect(listboxInstance.listKeyManager.activeItem).toBe(optionInstances[0]);
123123

124124
dispatchKeyboardEvent(listboxElement, 'keydown', END);
125125
fixture.detectChanges();
126126

127-
expect(listboxInstance._listKeyManager.activeItem).toBe(optionInstances[3]);
127+
expect(listboxInstance.listKeyManager.activeItem).toBe(optionInstances[3]);
128128
});
129129

130130
it('should be able to toggle listbox disabled state', () => {
@@ -210,15 +210,15 @@ describe('CdkOption and CdkListbox', () => {
210210
});
211211

212212
it('should change active item using type ahead', fakeAsync(() => {
213-
expect(listboxInstance._listKeyManager.activeItem).toBeNull();
214-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(-1);
213+
expect(listboxInstance.listKeyManager.activeItem).toBeNull();
214+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(-1);
215215

216216
dispatchKeyboardEvent(listboxElement, 'keydown', A);
217217
fixture.detectChanges();
218218
tick(200);
219219

220-
expect(listboxInstance._listKeyManager.activeItem).toEqual(optionInstances[2]);
221-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(2);
220+
expect(listboxInstance.listKeyManager.activeItem).toEqual(optionInstances[2]);
221+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(2);
222222
}));
223223

224224
it('should not handle space or enter on a disabled listbox', () => {
@@ -240,8 +240,8 @@ describe('CdkOption and CdkListbox', () => {
240240
});
241241

242242
it('should not handle type ahead on a disabled listbox', fakeAsync(() => {
243-
expect(listboxInstance._listKeyManager.activeItem).toBeNull();
244-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(-1);
243+
expect(listboxInstance.listKeyManager.activeItem).toBeNull();
244+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(-1);
245245

246246
testComponent.isListboxDisabled = true;
247247
fixture.detectChanges();
@@ -250,8 +250,8 @@ describe('CdkOption and CdkListbox', () => {
250250
fixture.detectChanges();
251251
tick(200);
252252

253-
expect(listboxInstance._listKeyManager.activeItem).toBeNull();
254-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(-1);
253+
expect(listboxInstance.listKeyManager.activeItem).toBeNull();
254+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(-1);
255255
}));
256256

257257
it('should not select a disabled option using space or enter', () => {
@@ -273,38 +273,38 @@ describe('CdkOption and CdkListbox', () => {
273273
});
274274

275275
it('should update active item upon arrow key presses', () => {
276-
expect(listboxInstance._listKeyManager.activeItem).toBeNull();
277-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(-1);
276+
expect(listboxInstance.listKeyManager.activeItem).toBeNull();
277+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(-1);
278278

279279
dispatchKeyboardEvent(listboxElement, 'keydown', DOWN_ARROW);
280280
fixture.detectChanges();
281281

282-
expect(listboxInstance._listKeyManager.activeItem).toEqual(optionInstances[0]);
283-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(0);
282+
expect(listboxInstance.listKeyManager.activeItem).toEqual(optionInstances[0]);
283+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(0);
284284

285285
dispatchKeyboardEvent(listboxElement, 'keydown', DOWN_ARROW);
286286
fixture.detectChanges();
287287

288-
expect(listboxInstance._listKeyManager.activeItem).toEqual(optionInstances[1]);
289-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(1);
288+
expect(listboxInstance.listKeyManager.activeItem).toEqual(optionInstances[1]);
289+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(1);
290290
});
291291

292292
it('should skip disabled options when navigating with arrow keys', () => {
293-
expect(listboxInstance._listKeyManager.activeItem).toBeNull();
294-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(-1);
293+
expect(listboxInstance.listKeyManager.activeItem).toBeNull();
294+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(-1);
295295

296296
testComponent.isSolarDisabled = true;
297297
dispatchKeyboardEvent(listboxElement, 'keydown', DOWN_ARROW);
298298
fixture.detectChanges();
299299

300-
expect(listboxInstance._listKeyManager.activeItem).toEqual(optionInstances[0]);
301-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(0);
300+
expect(listboxInstance.listKeyManager.activeItem).toEqual(optionInstances[0]);
301+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(0);
302302

303303
dispatchKeyboardEvent(listboxElement, 'keydown', DOWN_ARROW);
304304
fixture.detectChanges();
305305

306-
expect(listboxInstance._listKeyManager.activeItem).toEqual(optionInstances[2]);
307-
expect(listboxInstance._listKeyManager.activeItemIndex).toBe(2);
306+
expect(listboxInstance.listKeyManager.activeItem).toEqual(optionInstances[2]);
307+
expect(listboxInstance.listKeyManager.activeItemIndex).toBe(2);
308308
});
309309

310310
it('should update selected option on click event', () => {
@@ -903,7 +903,7 @@ class ListboxWithOptions {
903903
isPurpleDisabled: boolean = false;
904904
isSolarDisabled: boolean = false;
905905

906-
onSelectionChange(event: ListboxSelectionChangeEvent<unknown>) {
906+
onSelectionChange(event: ListboxValueChangeEvent<unknown>) {
907907
this.changedOption = event.option;
908908
}
909909
}
@@ -923,7 +923,7 @@ class ListboxMultiselect {
923923
changedOption: CdkOption;
924924
isMultiselectable: boolean = false;
925925

926-
onSelectionChange(event: ListboxSelectionChangeEvent<unknown>) {
926+
onSelectionChange(event: ListboxValueChangeEvent<unknown>) {
927927
this.changedOption = event.option;
928928
}
929929
}
@@ -943,7 +943,7 @@ class ListboxActiveDescendant {
943943
isActiveDescendant: boolean = true;
944944
focusedOption: string;
945945

946-
onSelectionChange(event: ListboxSelectionChangeEvent<unknown>) {
946+
onSelectionChange(event: ListboxValueChangeEvent<unknown>) {
947947
this.changedOption = event.option;
948948
}
949949

@@ -974,7 +974,7 @@ class ListboxControlValueAccessor {
974974
showListbox: boolean = true;
975975
@ViewChild(CdkListbox) listbox: CdkListbox<string>;
976976

977-
onSelectionChange(event: ListboxSelectionChangeEvent<string>) {
977+
onSelectionChange(event: ListboxValueChangeEvent<string>) {
978978
this.changedOption = event.option;
979979
}
980980
}
@@ -1007,7 +1007,7 @@ class ListboxInsideCombobox {
10071007
@ViewChild(CdkListbox) listbox: CdkListbox<string>;
10081008
@ViewChild(CdkCombobox) combobox: CdkCombobox;
10091009

1010-
onSelectionChange(event: ListboxSelectionChangeEvent<string>) {
1010+
onSelectionChange(event: ListboxValueChangeEvent<string>) {
10111011
this.changedOption = event.option;
10121012
}
10131013
}

0 commit comments

Comments
 (0)