Skip to content

Commit 0aa99c0

Browse files
committed
fixup! fix(cdk-experimental/ui-patterns) toolbar fix for focus change
1 parent 6371abe commit 0aa99c0

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ export class ListFocus<T extends ListFocusItem> {
4848
prevActiveItem = signal<T | undefined>(undefined);
4949

5050
/** The index of the last item that was active. */
51-
prevActiveIndex = computed(() => this.prevActiveItem()?.index() ?? -1);
51+
prevActiveIndex = computed(() => {
52+
return this.prevActiveItem() ? this.inputs.items().indexOf(this.prevActiveItem()!) : -1;
53+
});
5254

5355
/** The current active index in the list. */
54-
activeIndex = computed(() => this.inputs.activeItem()?.index() ?? -1);
56+
activeIndex = computed(() => {
57+
return this.inputs.activeItem() ? this.inputs.items().indexOf(this.inputs.activeItem()!) : -1;
58+
});
5559

5660
constructor(readonly inputs: ListFocusInputs<T>) {}
5761

src/cdk-experimental/ui-patterns/radio-group/radio-group.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface ToolbarLike<V> {
4343
/** Controls the state of a radio group. */
4444
export class RadioGroupPattern<V> {
4545
/** The list behavior for the radio group. */
46-
readonly listBehavior: List<RadioButtonPattern<V>, V>;
46+
readonly listBehavior: List<RadioButtonPattern<V> | ToolbarWidget, V>;
4747

4848
/** Whether the radio group is vertically or horizontally oriented. */
4949
orientation: SignalLike<'vertical' | 'horizontal'>;
@@ -132,9 +132,10 @@ export class RadioGroupPattern<V> {
132132

133133
this.listBehavior = new List({
134134
...inputs,
135-
wrap: () => false,
135+
activeItem: inputs.toolbar()?.listBehavior.inputs.activeItem ?? inputs.activeItem,
136+
wrap: () => !!inputs.toolbar(),
136137
multi: () => false,
137-
selectionMode: () => 'follow',
138+
selectionMode: () => (inputs.toolbar() ? 'explicit' : 'follow'),
138139
typeaheadDelay: () => 0, // Radio groups do not support typeahead.
139140
});
140141
}

src/cdk-experimental/ui-patterns/toolbar/toolbar.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,18 @@ export class ToolbarPattern<V> {
6868
.on(' ', () => this.toolbarSelectOverride())
6969
.on('Enter', () => this.toolbarSelectOverride())
7070
.on(this.prevKey, () => this.listBehavior.prev())
71-
.on(this.nextKey, () => {
72-
console.log('next');
73-
this.next();
71+
.on('ArrowDown', () => {
72+
const activeItem = this.inputs.activeItem();
73+
if (activeItem instanceof RadioButtonPattern && activeItem.group()!!) {
74+
activeItem.group()?.listBehavior.next();
75+
} else {
76+
this.listBehavior.next();
77+
}
7478
})
79+
.on('ArrowRight', () => this.listBehavior.next())
7580
.on('Home', () => this.listBehavior.first())
7681
.on('End', () => this.listBehavior.last());
7782
});
78-
next() {
79-
const activeItem = this.inputs.activeItem();
80-
// if (activeItem instanceof RadioButtonPattern && activeItem.group()!!) {
81-
// console.log('let the group move itself');
82-
// activeItem.group()!!.listBehavior.next();
83-
// } else
84-
this.listBehavior.next();
85-
// find what is the next item
86-
// console.log('next item', this.listBehavior.nextItem());
87-
}
8883

8984
toolbarSelectOverride() {
9085
const activeItem = this.inputs.activeItem();

0 commit comments

Comments
 (0)