Skip to content

Commit 1fdfca5

Browse files
committed
fix(aria/tree): add validation for single selection tree with multiple values
1 parent 900a5e8 commit 1fdfca5

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
@@ -780,7 +780,6 @@ export class ToolbarPattern<V> {
780780
setDefaultState(): void;
781781
readonly softDisabled: SignalLike<boolean>;
782782
readonly tabIndex: SignalLike<0 | -1>;
783-
validate(): string[];
784783
}
785784

786785
// @public
@@ -917,6 +916,7 @@ export class TreePattern<V> implements TreeInputs<V> {
917916
readonly treeBehavior: Tree<TreeItemPattern<V>, V>;
918917
readonly typeaheadDelay: SignalLike<number>;
919918
readonly typeaheadRegexp: RegExp;
919+
validate(): string[];
920920
readonly values: WritableSignalLike<V[]>;
921921
readonly visible: () => boolean;
922922
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)