From 11f812c2a934c3f01112be22db19209f4e865661 Mon Sep 17 00:00:00 2001 From: Sam Richardson Date: Tue, 17 Oct 2023 11:11:37 -0400 Subject: [PATCH] fix(checkbox): correctly set label when using forge label --- src/lib/checkbox/checkbox-adapter.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/checkbox/checkbox-adapter.ts b/src/lib/checkbox/checkbox-adapter.ts index 4be68cf96..33bf40a29 100644 --- a/src/lib/checkbox/checkbox-adapter.ts +++ b/src/lib/checkbox/checkbox-adapter.ts @@ -129,9 +129,7 @@ export class CheckboxAdapter extends BaseAdapter implements public proxyLabel(value: string | null): void { this._labelElementText = value ?? undefined; - if (!this._forwardedAriaLabel) { - toggleAttribute(this._activeInputElement, !!value, 'aria-label', value ?? undefined); - } + this._setAriaLabel(); } public syncValue(value: string | null, state: CheckboxState): void { @@ -162,11 +160,16 @@ export class CheckboxAdapter extends BaseAdapter implements // it can be used to determine whether an updated label element should take effect. if (name === 'aria-label') { this._forwardedAriaLabel = value ?? undefined; - toggleAttribute(el, !!value || !!this._labelElementText, name, value ?? this._labelElementText); + this._setAriaLabel(); return; } // Otherwise forward the attribute to the element. toggleAttribute(el, !!value, name, value ?? undefined); }); } + + private _setAriaLabel(): void { + const hasAriaLabel = !!this._forwardedAriaLabel || !!this._labelElementText; + toggleAttribute(this._activeInputElement, hasAriaLabel, 'aria-label', this._forwardedAriaLabel ?? this._labelElementText); + } }