Skip to content

Commit dbb94dc

Browse files
authored
[aria/multiple] Add to and clean up input validation across aria components (#32713)
* fix(aria/toolbar): remove unnnecessary validation methods * fix(aria/tree): add validation for single selection tree with multiple values
1 parent 82a51f3 commit dbb94dc

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

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/toolbar/toolbar.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,4 @@ export class ToolbarPattern<V> {
198198
this.inputs.activeItem.set(firstItem);
199199
}
200200
}
201-
202-
/** Validates the state of the toolbar and returns a list of accessibility violations. */
203-
validate(): string[] {
204-
const violations: string[] = [];
205-
return violations;
206-
}
207201
}

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/toolbar/toolbar.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,6 @@ export class Toolbar<V> {
109109
private _hasBeenFocused = signal(false);
110110

111111
constructor() {
112-
afterRenderEffect(() => {
113-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
114-
const violations = this._pattern.validate();
115-
for (const violation of violations) {
116-
console.error(violation);
117-
}
118-
}
119-
});
120-
121112
afterRenderEffect(() => {
122113
if (!this._hasBeenFocused()) {
123114
this._pattern.setDefaultState();

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)