Skip to content

Commit

Permalink
fix(checkbox): correctly set label when using forge label
Browse files Browse the repository at this point in the history
  • Loading branch information
samrichardsontylertech committed Oct 17, 2023
1 parent 22b474f commit 11f812c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/checkbox/checkbox-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export class CheckboxAdapter extends BaseAdapter<ICheckboxComponent> 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 {
Expand Down Expand Up @@ -162,11 +160,16 @@ export class CheckboxAdapter extends BaseAdapter<ICheckboxComponent> 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);
}
}

0 comments on commit 11f812c

Please sign in to comment.