diff --git a/goldens/aria/private/index.api.md b/goldens/aria/private/index.api.md index 16d033b82147..79b95f8a8f26 100644 --- a/goldens/aria/private/index.api.md +++ b/goldens/aria/private/index.api.md @@ -781,7 +781,6 @@ export class ToolbarPattern { setDefaultState(): void; readonly softDisabled: SignalLike; readonly tabIndex: SignalLike<0 | -1>; - validate(): string[]; } // @public @@ -918,6 +917,7 @@ export class TreePattern implements TreeInputs { readonly treeBehavior: Tree, V>; readonly typeaheadDelay: SignalLike; readonly typeaheadRegexp: RegExp; + validate(): string[]; readonly values: WritableSignalLike; readonly visible: () => boolean; readonly wrap: SignalLike; diff --git a/src/aria/private/toolbar/toolbar.ts b/src/aria/private/toolbar/toolbar.ts index 1bdd4b78fdcc..25396ad6fe22 100644 --- a/src/aria/private/toolbar/toolbar.ts +++ b/src/aria/private/toolbar/toolbar.ts @@ -198,10 +198,4 @@ export class ToolbarPattern { this.inputs.activeItem.set(firstItem); } } - - /** Validates the state of the toolbar and returns a list of accessibility violations. */ - validate(): string[] { - const violations: string[] = []; - return violations; - } } diff --git a/src/aria/private/tree/tree.ts b/src/aria/private/tree/tree.ts index e88d1955a7c5..4095b643b7bf 100644 --- a/src/aria/private/tree/tree.ts +++ b/src/aria/private/tree/tree.ts @@ -358,6 +358,19 @@ export class TreePattern implements TreeInputs { }); } + /** Returns a set of violations */ + validate(): string[] { + const violations: string[] = []; + + if (!this.inputs.multi() && this.inputs.values().length > 1) { + violations.push( + `A single-select tree should not have multiple selected options. Selected options: ${this.inputs.values().join(', ')}`, + ); + } + + return violations; + } + /** * Sets the tree to it's default initial state. * diff --git a/src/aria/toolbar/toolbar.ts b/src/aria/toolbar/toolbar.ts index c1ef0774966a..f99ce45da71a 100644 --- a/src/aria/toolbar/toolbar.ts +++ b/src/aria/toolbar/toolbar.ts @@ -109,15 +109,6 @@ export class Toolbar { private _hasBeenFocused = signal(false); constructor() { - afterRenderEffect(() => { - if (typeof ngDevMode === 'undefined' || ngDevMode) { - const violations = this._pattern.validate(); - for (const violation of violations) { - console.error(violation); - } - } - }); - afterRenderEffect(() => { if (!this._hasBeenFocused()) { this._pattern.setDefaultState(); diff --git a/src/aria/tree/tree.ts b/src/aria/tree/tree.ts index 837031088499..d08cc870cbc0 100644 --- a/src/aria/tree/tree.ts +++ b/src/aria/tree/tree.ts @@ -174,6 +174,15 @@ export class Tree { this._popup?._controls?.set(this._pattern as ComboboxTreePattern); } + afterRenderEffect(() => { + if (typeof ngDevMode === 'undefined' || ngDevMode) { + const violations = this._pattern.validate(); + for (const violation of violations) { + console.error(violation); + } + } + }); + afterRenderEffect(() => { if (!this._hasFocused()) { this._pattern.setDefaultState();