Skip to content

Commit d50e6e3

Browse files
committed
fix(cdk-experimental/ui-patterns) toolbar logic and readibility improvement
1 parent da7c654 commit d50e6e3

File tree

6 files changed

+14
-32
lines changed

6 files changed

+14
-32
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class CdkRadioGroup<V> {
103103
toolbar = inject(CdkToolbar, {optional: true});
104104

105105
/** Toolbar pattern if applicable */
106-
private readonly _toolbarPattern = computed(() => (this.toolbar ? this.toolbar.pattern : null));
106+
private readonly _toolbarPattern = computed(() => this.toolbar?.pattern);
107107

108108
/** The RadioButton UIPatterns of the child CdkRadioButtons. */
109109
protected items = computed(() => this._cdkRadioButtons().map(radio => radio.pattern));
@@ -140,7 +140,7 @@ export class CdkRadioGroup<V> {
140140
activeItem: signal(undefined),
141141
textDirection: this.textDirection,
142142
toolbar: this._toolbarPattern,
143-
focusMode: this._toolbarPattern() ? this._toolbarPattern()!!.inputs.focusMode : this.focusMode,
143+
focusMode: this._toolbarPattern()?.inputs.focusMode ?? this.focusMode,
144144
});
145145

146146
/** Whether the radio group has received focus yet. */

src/cdk-experimental/toolbar/toolbar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class CdkToolbarWidget implements OnInit, OnDestroy {
201201
...this,
202202
id: this.id,
203203
element: this.element,
204-
disabled: computed(() => this._cdkToolbar.disabled() || this.disabled() || false),
204+
disabled: computed(() => this._cdkToolbar.disabled() || this.disabled()),
205205
parentToolbar: this.parentToolbar,
206206
});
207207

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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 ToolbarWidget = {
17+
type ToolbarWidgetLike = {
1818
id: SignalLike<string>;
1919
index: SignalLike<number>;
2020
element: SignalLike<HTMLElement>;
@@ -25,7 +25,7 @@ type ToolbarWidget = {
2525

2626
interface RadioGroupLike<V> {
2727
/** The list behavior for the radio group. */
28-
listBehavior: List<RadioButtonPattern<V> | ToolbarWidget, V>;
28+
listBehavior: List<RadioButtonPattern<V> | ToolbarWidgetLike, V>;
2929
/** Whether the list is readonly */
3030
readonly: SignalLike<boolean>;
3131
/** Whether the radio group is disabled. */

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export type RadioGroupInputs<V> = Omit<
2323
/** Whether the radio group is readonly. */
2424
readonly: SignalLike<boolean>;
2525
/** Parent toolbar of radio group */
26-
toolbar: SignalLike<ToolbarLike<V> | null>;
26+
toolbar: SignalLike<ToolbarLike<V> | undefined>;
2727
};
2828

29-
type ToolbarWidget = {
29+
type ToolbarWidgetLike = {
3030
id: SignalLike<string>;
3131
index: SignalLike<number>;
3232
element: SignalLike<HTMLElement>;
@@ -36,14 +36,14 @@ type ToolbarWidget = {
3636
};
3737

3838
interface ToolbarLike<V> {
39-
listBehavior: List<RadioButtonPattern<V> | ToolbarWidget, V>;
39+
listBehavior: List<RadioButtonPattern<V> | ToolbarWidgetLike, V>;
4040
orientation: SignalLike<'vertical' | 'horizontal'>;
4141
disabled: SignalLike<boolean>;
4242
}
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> | ToolbarWidget, V>;
46+
readonly listBehavior: List<RadioButtonPattern<V> | ToolbarWidgetLike, V>;
4747

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

129129
constructor(readonly inputs: RadioGroupInputs<V>) {
130130
this.orientation =
131-
inputs.toolbar() !== null ? inputs.toolbar()!.orientation : inputs.orientation;
131+
inputs.toolbar() !== undefined ? inputs.toolbar()!.orientation : inputs.orientation;
132132

133133
this.listBehavior = new List({
134134
...inputs,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('RadioGroup Pattern', () => {
3939
focusMode: inputs.focusMode ?? signal('roving'),
4040
textDirection: inputs.textDirection ?? signal('ltr'),
4141
orientation: inputs.orientation ?? signal('vertical'),
42-
toolbar: inputs.toolbar ?? signal(null),
42+
toolbar: inputs.toolbar ?? signal(undefined),
4343
});
4444
}
4545

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@
88

99
import {computed, signal} from '@angular/core';
1010
import {KeyboardEventManager, PointerEventManager} from '../behaviors/event-manager';
11-
// import {ListFocus, ListFocusInputs, ListFocusItem} from '../behaviors/list-focus/list-focus';
12-
// import {
13-
// ListNavigation,
14-
// ListNavigationInputs,
15-
// ListNavigationItem,
16-
// } from '../behaviors/list-navigation/list-navigation';
1711
import {SignalLike} from '../behaviors/signal-like/signal-like';
1812

1913
import {RadioButtonPattern} from '../radio-group/radio-button';
2014

2115
import {List, ListInputs, ListItem} from '../behaviors/list/list';
2216

23-
// remove typeahead etc.
2417
export type ToolbarInputs<V> = Omit<
2518
ListInputs<ToolbarWidgetPattern | RadioButtonPattern<V>, V>,
2619
'multi' | 'typeaheadDelay' | 'value' | 'selectionMode'
2720
>;
28-
// ListInputs<ToolbarWidgetPattern | RadioButtonPattern<V>, V>;
2921

3022
export class ToolbarPattern<V> {
3123
/** The list behavior for the toolbar. */
@@ -35,7 +27,7 @@ export class ToolbarPattern<V> {
3527
readonly orientation: SignalLike<'vertical' | 'horizontal'>;
3628

3729
/** Whether the toolbar is disabled. */
38-
disabled = computed(() => this.inputs.disabled() || this.listBehavior.disabled());
30+
disabled = computed(() => this.listBehavior.disabled());
3931

4032
/** The tabindex of the toolbar (if using activedescendant). */
4133
tabindex = computed(() => this.listBehavior.tabindex());
@@ -86,15 +78,15 @@ export class ToolbarPattern<V> {
8678
.on(this.nextKey, () => this.listBehavior.next())
8779
.on(this.altNextKey, () => {
8880
const activeItem = this.inputs.activeItem();
89-
if (activeItem instanceof RadioButtonPattern && activeItem.group()!!) {
81+
if (activeItem instanceof RadioButtonPattern && activeItem.group()) {
9082
activeItem.group()?.listBehavior.next();
9183
} else {
9284
this.listBehavior.next();
9385
}
9486
})
9587
.on(this.altPrevKey, () => {
9688
const activeItem = this.inputs.activeItem();
97-
if (activeItem instanceof RadioButtonPattern && activeItem.group()!!) {
89+
if (activeItem instanceof RadioButtonPattern && activeItem.group()) {
9890
activeItem.group()?.listBehavior.prev();
9991
} else {
10092
this.listBehavior.prev();
@@ -222,13 +214,6 @@ export class ToolbarPattern<V> {
222214
}
223215
}
224216

225-
export type ToolbarWidget = {
226-
id: SignalLike<string>;
227-
index: SignalLike<number>;
228-
element: SignalLike<HTMLElement>;
229-
disabled: SignalLike<boolean>;
230-
};
231-
232217
/** Represents the required inputs for a toolbar widget in a toolbar. */
233218
export interface ToolbarWidgetInputs extends Omit<ListItem<any>, 'searchTerm' | 'value' | 'index'> {
234219
/** A reference to the parent toolbar. */
@@ -267,6 +252,3 @@ export class ToolbarWidgetPattern {
267252
this.parentToolbar = inputs.parentToolbar;
268253
}
269254
}
270-
271-
// can remove later
272-
export type ToolbarPatternType<V> = InstanceType<typeof ToolbarPattern<V>>;

0 commit comments

Comments
 (0)