Skip to content

Commit 8d8afa8

Browse files
committed
fixup! test(cdk-experimental/combobox): add unit tests
1 parent ea2d807 commit 8d8afa8

File tree

8 files changed

+152
-155
lines changed

8 files changed

+152
-155
lines changed

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

Lines changed: 74 additions & 57 deletions
Large diffs are not rendered by default.

src/cdk-experimental/combobox/combobox.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
ElementRef,
1414
inject,
1515
input,
16-
model,
1716
signal,
1817
WritableSignal,
1918
} from '@angular/core';
@@ -54,9 +53,6 @@ export class CdkCombobox<V> {
5453
/** Whether the combobox is focused. */
5554
readonly isFocused = signal(false);
5655

57-
/** The values of the current selected items. */
58-
value = model<V | undefined>(undefined);
59-
6056
/** The function used to filter the options in the popup based on the input text. */
6157
filter = input<(inputText: string, itemText: string) => boolean>((inputText, itemText) =>
6258
itemText.toLowerCase().includes(inputText.toLowerCase()),
@@ -69,33 +65,22 @@ export class CdkCombobox<V> {
6965
readonly pattern = new ComboboxPattern<any, V>({
7066
...this,
7167
inputEl: signal(undefined),
72-
containerEl: signal(undefined),
68+
containerEl: () => this._elementRef.nativeElement,
7369
popupControls: () => this.popup()?.controls(),
7470
});
7571

7672
constructor() {
77-
(this.pattern.inputs.containerEl as WritableSignal<HTMLElement>).set(
78-
this._elementRef.nativeElement,
79-
);
80-
8173
afterRenderEffect(() => {
82-
this._deferredContentAware?.contentVisible.set(this.pattern.isFocused());
74+
if (!this._deferredContentAware?.contentVisible() && this.pattern.isFocused()) {
75+
this._deferredContentAware?.contentVisible.set(true);
76+
}
8377
});
8478

8579
afterRenderEffect(() => {
8680
if (!this._hasBeenFocused() && this.pattern.isFocused()) {
8781
this._hasBeenFocused.set(true);
8882
}
8983
});
90-
91-
afterRenderEffect(() => {
92-
if (!this._hasBeenFocused()) {
93-
if (this.value() !== undefined) {
94-
this._deferredContentAware?.contentVisible.set(false);
95-
this.pattern.setDefaultState();
96-
}
97-
}
98-
});
9984
}
10085
}
10186

src/cdk-experimental/listbox/listbox.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ export class CdkListbox<V> {
158158
}
159159
});
160160

161+
// Ensure that if the active item is removed from
162+
// the list, the listbox updates it's focus state.
161163
afterRenderEffect(() => {
162164
const items = inputs.items();
163165
const activeItem = untracked(() => inputs.activeItem());
@@ -167,13 +169,13 @@ export class CdkListbox<V> {
167169
}
168170
});
169171

172+
// Ensure that the value is always in sync with the available options.
170173
afterRenderEffect(() => {
171174
const items = inputs.items();
172175
const value = untracked(() => this.value());
173176

174177
if (items && value.some(v => !items.some(i => i.value() === v))) {
175178
this.value.set(value.filter(v => items.some(i => i.value() === v)));
176-
this._popup?.combobox?.pattern?.inputs.value.set(this.value()[0]);
177179
}
178180
});
179181
}

src/cdk-experimental/tree/tree.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export class CdkTree<V> {
183183

184184
if (items && value.some(v => !items.some(i => i.value() === v))) {
185185
this.value.set(value.filter(v => items.some(i => i.value() === v)));
186-
this._popup?.combobox?.pattern?.inputs.value.set(this.value()[0]);
187186
}
188187
});
189188
}

0 commit comments

Comments
 (0)