@@ -22,12 +22,37 @@ export type RadioGroupInputs<V> = Omit<
22
22
23
23
/** Whether the radio group is readonly. */
24
24
readonly : SignalLike < boolean > ;
25
+ /** Parent toolbar of radio group */
26
+ toolbar : SignalLike < ToolbarLike < V > | undefined > ;
25
27
} ;
26
28
29
+ /**
30
+ * Represents the properties exposed by a toolbar widget that need to be accessed by a radio group.
31
+ * This exists to avoid circular dependency errors between the toolbar and radio button.
32
+ */
33
+ type ToolbarWidgetLike = {
34
+ id : SignalLike < string > ;
35
+ index : SignalLike < number > ;
36
+ element : SignalLike < HTMLElement > ;
37
+ disabled : SignalLike < boolean > ;
38
+ searchTerm : SignalLike < any > ;
39
+ value : SignalLike < any > ;
40
+ } ;
41
+
42
+ /**
43
+ * Represents the properties exposed by a toolbar that need to be accessed by a radio group.
44
+ * This exists to avoid circular dependency errors between the toolbar and radio button.
45
+ */
46
+ export interface ToolbarLike < V > {
47
+ listBehavior : List < RadioButtonPattern < V > | ToolbarWidgetLike , V > ;
48
+ orientation : SignalLike < 'vertical' | 'horizontal' > ;
49
+ disabled : SignalLike < boolean > ;
50
+ }
51
+
27
52
/** Controls the state of a radio group. */
28
53
export class RadioGroupPattern < V > {
29
54
/** The list behavior for the radio group. */
30
- readonly listBehavior : List < RadioButtonPattern < V > , V > ;
55
+ readonly listBehavior : List < RadioButtonPattern < V > | ToolbarWidgetLike , V > ;
31
56
32
57
/** Whether the radio group is vertically or horizontally oriented. */
33
58
orientation : SignalLike < 'vertical' | 'horizontal' > ;
@@ -41,8 +66,8 @@ export class RadioGroupPattern<V> {
41
66
/** Whether the radio group is readonly. */
42
67
readonly = computed ( ( ) => this . selectedItem ( ) ?. disabled ( ) || this . inputs . readonly ( ) ) ;
43
68
44
- /** The tabindex of the radio group (if using activedescendant) . */
45
- tabindex = computed ( ( ) => this . listBehavior . tabindex ( ) ) ;
69
+ /** The tabindex of the radio group. */
70
+ tabindex = computed ( ( ) => ( this . inputs . toolbar ( ) ? - 1 : this . listBehavior . tabindex ( ) ) ) ;
46
71
47
72
/** The id of the current active radio button (if using activedescendant). */
48
73
activedescendant = computed ( ( ) => this . listBehavior . activedescendant ( ) ) ;
@@ -67,6 +92,11 @@ export class RadioGroupPattern<V> {
67
92
keydown = computed ( ( ) => {
68
93
const manager = new KeyboardEventManager ( ) ;
69
94
95
+ // When within a toolbar relinquish keyboard control
96
+ if ( this . inputs . toolbar ( ) ) {
97
+ return manager ;
98
+ }
99
+
70
100
// Readonly mode allows navigation but not selection changes.
71
101
if ( this . readonly ( ) ) {
72
102
return manager
@@ -91,6 +121,11 @@ export class RadioGroupPattern<V> {
91
121
pointerdown = computed ( ( ) => {
92
122
const manager = new PointerEventManager ( ) ;
93
123
124
+ // When within a toolbar relinquish pointer control
125
+ if ( this . inputs . toolbar ( ) ) {
126
+ return manager ;
127
+ }
128
+
94
129
if ( this . readonly ( ) ) {
95
130
// Navigate focus only in readonly mode.
96
131
return manager . on ( e => this . listBehavior . goto ( this . _getItem ( e ) ! ) ) ;
@@ -101,13 +136,15 @@ export class RadioGroupPattern<V> {
101
136
} ) ;
102
137
103
138
constructor ( readonly inputs : RadioGroupInputs < V > ) {
104
- this . orientation = inputs . orientation ;
139
+ this . orientation =
140
+ inputs . toolbar ( ) !== undefined ? inputs . toolbar ( ) ! . orientation : inputs . orientation ;
105
141
106
142
this . listBehavior = new List ( {
107
143
...inputs ,
108
- wrap : ( ) => false ,
144
+ activeItem : inputs . toolbar ( ) ?. listBehavior . inputs . activeItem ?? inputs . activeItem ,
145
+ wrap : ( ) => ! ! inputs . toolbar ( ) ,
109
146
multi : ( ) => false ,
110
- selectionMode : ( ) => ' follow',
147
+ selectionMode : ( ) => ( inputs . toolbar ( ) ? 'explicit' : ' follow') ,
111
148
typeaheadDelay : ( ) => 0 , // Radio groups do not support typeahead.
112
149
} ) ;
113
150
}
0 commit comments