@@ -22,12 +22,37 @@ export type RadioGroupInputs<V> = Omit<
2222
2323 /** Whether the radio group is readonly. */
2424 readonly : SignalLike < boolean > ;
25+ /** Parent toolbar of radio group */
26+ toolbar : SignalLike < ToolbarLike < V > | undefined > ;
2527} ;
2628
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+
2752/** Controls the state of a radio group. */
2853export class RadioGroupPattern < V > {
2954 /** The list behavior for the radio group. */
30- readonly listBehavior : List < RadioButtonPattern < V > , V > ;
55+ readonly listBehavior : List < RadioButtonPattern < V > | ToolbarWidgetLike , V > ;
3156
3257 /** Whether the radio group is vertically or horizontally oriented. */
3358 orientation : SignalLike < 'vertical' | 'horizontal' > ;
@@ -41,8 +66,8 @@ export class RadioGroupPattern<V> {
4166 /** Whether the radio group is readonly. */
4267 readonly = computed ( ( ) => this . selectedItem ( ) ?. disabled ( ) || this . inputs . readonly ( ) ) ;
4368
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 ( ) ) ) ;
4671
4772 /** The id of the current active radio button (if using activedescendant). */
4873 activedescendant = computed ( ( ) => this . listBehavior . activedescendant ( ) ) ;
@@ -67,6 +92,11 @@ export class RadioGroupPattern<V> {
6792 keydown = computed ( ( ) => {
6893 const manager = new KeyboardEventManager ( ) ;
6994
95+ // When within a toolbar relinquish keyboard control
96+ if ( this . inputs . toolbar ( ) ) {
97+ return manager ;
98+ }
99+
70100 // Readonly mode allows navigation but not selection changes.
71101 if ( this . readonly ( ) ) {
72102 return manager
@@ -91,6 +121,11 @@ export class RadioGroupPattern<V> {
91121 pointerdown = computed ( ( ) => {
92122 const manager = new PointerEventManager ( ) ;
93123
124+ // When within a toolbar relinquish pointer control
125+ if ( this . inputs . toolbar ( ) ) {
126+ return manager ;
127+ }
128+
94129 if ( this . readonly ( ) ) {
95130 // Navigate focus only in readonly mode.
96131 return manager . on ( e => this . listBehavior . goto ( this . _getItem ( e ) ! ) ) ;
@@ -101,13 +136,15 @@ export class RadioGroupPattern<V> {
101136 } ) ;
102137
103138 constructor ( readonly inputs : RadioGroupInputs < V > ) {
104- this . orientation = inputs . orientation ;
139+ this . orientation =
140+ inputs . toolbar ( ) !== undefined ? inputs . toolbar ( ) ! . orientation : inputs . orientation ;
105141
106142 this . listBehavior = new List ( {
107143 ...inputs ,
108- wrap : ( ) => false ,
144+ activeItem : inputs . toolbar ( ) ?. listBehavior . inputs . activeItem ?? inputs . activeItem ,
145+ wrap : ( ) => ! ! inputs . toolbar ( ) ,
109146 multi : ( ) => false ,
110- selectionMode : ( ) => ' follow',
147+ selectionMode : ( ) => ( inputs . toolbar ( ) ? 'explicit' : ' follow') ,
111148 typeaheadDelay : ( ) => 0 , // Radio groups do not support typeahead.
112149 } ) ;
113150 }
0 commit comments