Skip to content

Commit 32bb6b1

Browse files
committed
fix(aria/tree): add validation for single selection tree with multiple values
1 parent 48c2e59 commit 32bb6b1

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

goldens/aria/private/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ export class ToolbarPattern<V> {
781781
setDefaultState(): void;
782782
readonly softDisabled: SignalLike<boolean>;
783783
readonly tabIndex: SignalLike<0 | -1>;
784-
validate(): string[];
785784
}
786785

787786
// @public
@@ -918,6 +917,7 @@ export class TreePattern<V> implements TreeInputs<V> {
918917
readonly treeBehavior: Tree<TreeItemPattern<V>, V>;
919918
readonly typeaheadDelay: SignalLike<number>;
920919
readonly typeaheadRegexp: RegExp;
920+
validate(): string[];
921921
readonly values: WritableSignalLike<V[]>;
922922
readonly visible: () => boolean;
923923
readonly wrap: SignalLike<boolean>;

src/aria/private/tree/tree.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,19 @@ export class TreePattern<V> implements TreeInputs<V> {
358358
});
359359
}
360360

361+
/** Returns a set of violations */
362+
validate(): string[] {
363+
const violations: string[] = [];
364+
365+
if (!this.inputs.multi() && this.inputs.values().length > 1) {
366+
violations.push(
367+
`A single-select tree should not have multiple selected options. Selected options: ${this.inputs.values().join(', ')}`,
368+
);
369+
}
370+
371+
return violations;
372+
}
373+
361374
/**
362375
* Sets the tree to it's default initial state.
363376
*

src/aria/tree/tree.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ export class Tree<V> {
174174
this._popup?._controls?.set(this._pattern as ComboboxTreePattern<V>);
175175
}
176176

177+
afterRenderEffect(() => {
178+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
179+
const violations = this._pattern.validate();
180+
for (const violation of violations) {
181+
console.error(violation);
182+
}
183+
}
184+
});
185+
177186
afterRenderEffect(() => {
178187
if (!this._hasFocused()) {
179188
this._pattern.setDefaultState();

0 commit comments

Comments
 (0)