Skip to content

Commit 7343657

Browse files
authoredMar 13, 2025··
fix(cdk-experimental/ui-patterns): small fixes for internal compatibi… (#30625)
* fix(cdk-experimental/ui-patterns): small fixes for internal compatibility * fixup! fix(cdk-experimental/ui-patterns): small fixes for internal compatibility
1 parent 765f54d commit 7343657

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed
 

‎src/cdk-experimental/ui-patterns/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ts_library(
99
exclude = ["**/*.spec.ts"],
1010
),
1111
deps = [
12+
"//src/cdk-experimental/ui-patterns/behaviors/signal-like",
1213
"//src/cdk-experimental/ui-patterns/listbox",
1314
"@npm//@angular/core",
1415
],

‎src/cdk-experimental/ui-patterns/behaviors/list-focus/list-focus.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ListFocus<T extends ListFocusItem> {
3434
}
3535

3636
/** The id of the current active item. */
37-
getActiveDescendant(): String | undefined {
37+
getActiveDescendant(): string | undefined {
3838
if (this.inputs.focusMode() === 'roving') {
3939
return undefined;
4040
}

‎src/cdk-experimental/ui-patterns/behaviors/list-navigation/list-navigation.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export class ListNavigation<T extends ListNavigationItem> {
4141
/** The last index that was active. */
4242
prevActiveIndex = signal(0);
4343

44-
constructor(readonly inputs: ListNavigationInputs<T>) {
45-
this.prevActiveIndex.set(inputs.activeIndex());
46-
}
44+
constructor(readonly inputs: ListNavigationInputs<T>) {}
4745

4846
/** Navigates to the given item. */
4947
goto(item: T) {

‎src/cdk-experimental/ui-patterns/listbox/listbox.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class ListboxPattern {
259259
return;
260260
}
261261

262-
const element = e.target.closest('[cdkoption]'); // TODO: Use a different identifier.
262+
const element = e.target.closest('[role="option"]'); // TODO: Use a different identifier.
263263
return this.inputs.items().find(i => i.element() === element);
264264
}
265265
}

‎src/cdk-experimental/ui-patterns/listbox/option.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface OptionInputs
2929
ListSelectionItem,
3030
ListTypeaheadItem,
3131
ListFocusItem {
32-
listbox: SignalLike<ListboxPattern>;
32+
listbox: SignalLike<ListboxPattern | undefined>;
3333
}
3434

3535
/** Represents an option in a listbox. */
@@ -41,12 +41,12 @@ export class OptionPattern {
4141
index = computed(
4242
() =>
4343
this.listbox()
44-
.navigation.inputs.items()
44+
?.navigation.inputs.items()
4545
.findIndex(i => i.id() === this.id()) ?? -1,
4646
);
4747

4848
/** Whether the option is selected. */
49-
selected = computed(() => this.listbox().selection.inputs.selectedIds().includes(this.id()));
49+
selected = computed(() => this.listbox()?.selection.inputs.selectedIds().includes(this.id()));
5050

5151
/** Whether the option is disabled. */
5252
disabled: SignalLike<boolean>;
@@ -55,10 +55,10 @@ export class OptionPattern {
5555
searchTerm: SignalLike<string>;
5656

5757
/** A reference to the parent listbox. */
58-
listbox: SignalLike<ListboxPattern>;
58+
listbox: SignalLike<ListboxPattern | undefined>;
5959

6060
/** The tabindex of the option. */
61-
tabindex = computed(() => this.listbox().focusManager.getItemTabindex(this));
61+
tabindex = computed(() => this.listbox()?.focusManager.getItemTabindex(this));
6262

6363
/** The html element that should receive focus. */
6464
element: SignalLike<HTMLElement>;

‎src/cdk-experimental/ui-patterns/public-api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88

99
export * from './listbox/listbox';
1010
export * from './listbox/option';
11+
export * from './behaviors/signal-like/signal-like';

0 commit comments

Comments
 (0)
Please sign in to comment.