Skip to content

Commit 9d2e2fa

Browse files
committed
fixup! feat(cdk-experimental/radio): create radio group and button directives
1 parent ef789fd commit 9d2e2fa

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/cdk-experimental/radio/radio.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import {
10+
afterRenderEffect,
1011
AfterViewInit,
1112
booleanAttribute,
1213
computed,
1314
contentChildren,
1415
Directive,
15-
effect,
1616
ElementRef,
1717
inject,
1818
input,
@@ -56,7 +56,7 @@ import {_IdGenerator} from '@angular/cdk/a11y';
5656
'(focusin)': 'onFocus()',
5757
},
5858
})
59-
export class CdkRadioGroup<V> implements AfterViewInit {
59+
export class CdkRadioGroup<V> {
6060
/** The directionality (LTR / RTL) context for the application (or a subtree of it). */
6161
private readonly _directionality = inject(Directionality);
6262

@@ -74,9 +74,6 @@ export class CdkRadioGroup<V> implements AfterViewInit {
7474
/** Whether the radio group is vertically or horizontally oriented. */
7575
orientation = input<'vertical' | 'horizontal'>('horizontal');
7676

77-
/** Whether focus should wrap when navigating. */
78-
wrap = input(false, {transform: booleanAttribute}); // Radio groups typically don't wrap
79-
8077
/** Whether disabled items in the group should be skipped when navigating. */
8178
skipDisabled = input(true, {transform: booleanAttribute});
8279

@@ -111,17 +108,13 @@ export class CdkRadioGroup<V> implements AfterViewInit {
111108
private _isViewInitialized = signal(false);
112109

113110
constructor() {
114-
effect(() => {
115-
if (this._isViewInitialized() && !this._hasFocused()) {
111+
afterRenderEffect(() => {
112+
if (!this._hasFocused()) {
116113
this.pattern.setDefaultState();
117114
}
118115
});
119116
}
120117

121-
ngAfterViewInit() {
122-
this._isViewInitialized.set(true);
123-
}
124-
125118
onFocus() {
126119
this._hasFocused.set(true);
127120
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface SelectOptions {
2121
}
2222

2323
/** Represents the required inputs for a radio group. */
24-
export type RadioGroupInputs<V> = ListNavigationInputs<RadioButtonPattern<V>> &
24+
export type RadioGroupInputs<V> = Omit<ListNavigationInputs<RadioButtonPattern<V>>, 'wrap'> &
2525
// Radio groups are always single-select.
2626
Omit<ListSelectionInputs<RadioButtonPattern<V>, V>, 'multi' | 'selectionMode'> &
2727
ListFocusInputs<RadioButtonPattern<V>> & {
@@ -115,12 +115,15 @@ export class RadioGroupPattern<V> {
115115
this.orientation = inputs.orientation;
116116

117117
this.focusManager = new ListFocus(inputs);
118-
this.navigation = new ListNavigation({...inputs, focusManager: this.focusManager});
118+
this.navigation = new ListNavigation({
119+
...inputs,
120+
wrap: () => false,
121+
focusManager: this.focusManager,
122+
});
119123
this.selection = new ListSelection({
120124
...inputs,
121-
// Radio groups are always single-select and selection follows focus.
122-
multi: signal(false),
123-
selectionMode: signal('follow'),
125+
multi: () => false,
126+
selectionMode: () => 'follow',
124127
focusManager: this.focusManager,
125128
});
126129
}

0 commit comments

Comments
 (0)