Skip to content

Commit da7c654

Browse files
committed
feat(cdk-experimental/ui-patterns) toolbar inner group wrap navigation
1 parent 0aa99c0 commit da7c654

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ import {List, ListItem} from '../behaviors/list/list';
1414
* Represents the properties exposed by a radio group that need to be accessed by a radio button.
1515
* This exists to avoid circular dependency errors between the radio group and radio button.
1616
*/
17-
type GeneralWidget = {
17+
type ToolbarWidget = {
1818
id: SignalLike<string>;
19+
index: SignalLike<number>;
1920
element: SignalLike<HTMLElement>;
2021
disabled: SignalLike<boolean>;
22+
searchTerm: SignalLike<any>;
23+
value: SignalLike<any>;
2124
};
2225

2326
interface RadioGroupLike<V> {
2427
/** The list behavior for the radio group. */
25-
listBehavior: List<RadioButtonPattern<V>, V>;
28+
listBehavior: List<RadioButtonPattern<V> | ToolbarWidget, V>;
2629
/** Whether the list is readonly */
2730
readonly: SignalLike<boolean>;
31+
/** Whether the radio group is disabled. */
32+
disabled: SignalLike<boolean>;
2833
}
2934

3035
/** Represents the required inputs for a radio button in a radio group. */
@@ -42,7 +47,9 @@ export class RadioButtonPattern<V> {
4247
value: SignalLike<V>;
4348

4449
/** The position of the radio button within the group. */
45-
index = computed(() => this.group()?.listBehavior.inputs.items().indexOf(this) ?? -1);
50+
index: SignalLike<number> = computed(
51+
() => this.group()?.listBehavior.inputs.items().indexOf(this) ?? -1,
52+
);
4653

4754
/** Whether the radio button is currently the active one (focused). */
4855
active = computed(() => this.group()?.listBehavior.inputs.activeItem() === this);
@@ -75,5 +82,3 @@ export class RadioButtonPattern<V> {
7582
this.disabled = inputs.disabled;
7683
}
7784
}
78-
79-
export type RadioButtonPatternType<V> = InstanceType<typeof RadioButtonPattern<V>>;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ export class RadioGroupPattern<V> {
112112
pointerdown = computed(() => {
113113
const manager = new PointerEventManager();
114114

115-
// // If within a disabled toolbar relinquish pointer control
116-
// if (this.inputs.toolbar() && this.inputs.toolbar()!.disabled()) {
117-
// return manager;
118-
// }
115+
// When within a toolbar relinquish pointer control
116+
if (this.inputs.toolbar()) {
117+
return manager;
118+
}
119119

120120
if (this.readonly()) {
121121
// Navigate focus only in readonly mode.

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {KeyboardEventManager, PointerEventManager} from '../behaviors/event-mana
1616
// } from '../behaviors/list-navigation/list-navigation';
1717
import {SignalLike} from '../behaviors/signal-like/signal-like';
1818

19-
import {RadioButtonPatternType, RadioButtonPattern} from '../radio-group/radio-button';
19+
import {RadioButtonPattern} from '../radio-group/radio-button';
2020

2121
import {List, ListInputs, ListItem} from '../behaviors/list/list';
2222

@@ -59,24 +59,47 @@ export class ToolbarPattern<V> {
5959
return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
6060
});
6161

62+
/** The alternate key used to navigate to the previous widget */
63+
altPrevKey = computed(() => {
64+
if (this.inputs.orientation() === 'vertical') {
65+
return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
66+
}
67+
return 'ArrowUp';
68+
});
69+
70+
/** The alternate key used to navigate to the next widget. */
71+
altNextKey = computed(() => {
72+
if (this.inputs.orientation() === 'vertical') {
73+
return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
74+
}
75+
return 'ArrowDown';
76+
});
77+
6278
/** The keydown event manager for the toolbar. */
6379
keydown = computed(() => {
6480
const manager = new KeyboardEventManager();
65-
console.log(' all curent itmes', this.inputs.items());
6681

6782
return manager
6883
.on(' ', () => this.toolbarSelectOverride())
6984
.on('Enter', () => this.toolbarSelectOverride())
7085
.on(this.prevKey, () => this.listBehavior.prev())
71-
.on('ArrowDown', () => {
86+
.on(this.nextKey, () => this.listBehavior.next())
87+
.on(this.altNextKey, () => {
7288
const activeItem = this.inputs.activeItem();
7389
if (activeItem instanceof RadioButtonPattern && activeItem.group()!!) {
7490
activeItem.group()?.listBehavior.next();
7591
} else {
7692
this.listBehavior.next();
7793
}
7894
})
79-
.on('ArrowRight', () => this.listBehavior.next())
95+
.on(this.altPrevKey, () => {
96+
const activeItem = this.inputs.activeItem();
97+
if (activeItem instanceof RadioButtonPattern && activeItem.group()!!) {
98+
activeItem.group()?.listBehavior.prev();
99+
} else {
100+
this.listBehavior.prev();
101+
}
102+
})
80103
.on('Home', () => this.listBehavior.first())
81104
.on('End', () => this.listBehavior.last());
82105
});
@@ -87,10 +110,9 @@ export class ToolbarPattern<V> {
87110
/** If the active item is a Radio Button, indicate to the group the selection */
88111
if (activeItem instanceof RadioButtonPattern) {
89112
const group = activeItem.group();
90-
if (group && !group.readonly()) {
113+
if (group && !group.readonly() && !group.disabled()) {
91114
group.listBehavior.selectOne();
92115
}
93-
// todo fix
94116
} else {
95117
/** Item is a Toolbar Widget, manually select it */
96118
if (activeItem && activeItem.element() && !activeItem.disabled())
@@ -112,9 +134,13 @@ export class ToolbarPattern<V> {
112134
if (!item) return;
113135

114136
if (item instanceof RadioButtonPattern) {
115-
// have the radio group handle the selection
137+
const group = item.group();
138+
if (group && !group.readonly() && !group.disabled()) {
139+
group.listBehavior.goto(item, {selectOne: true});
140+
}
141+
} else {
142+
this.listBehavior.goto(item);
116143
}
117-
this.listBehavior.goto(item);
118144
}
119145

120146
/** Handles keydown events for the toolbar. */
@@ -126,7 +152,6 @@ export class ToolbarPattern<V> {
126152

127153
/** Handles pointerdown events for the toolbar. */
128154
onPointerdown(event: PointerEvent) {
129-
console.log('this disabled', this.disabled());
130155
if (!this.disabled()) {
131156
this.pointerdown().handle(event);
132157
}
@@ -177,7 +202,6 @@ export class ToolbarPattern<V> {
177202
}
178203

179204
if (firstItem) {
180-
console.log('setting active item to', firstItem);
181205
this.inputs.activeItem.set(firstItem);
182206
}
183207
}

0 commit comments

Comments
 (0)