Skip to content

Commit 7a8e541

Browse files
authored
feat(ui5-checkbox): support associated labels with 'for' attribute (#11925)
- Add getAssociatedLabelForTexts() to ariaLabelText getter. - Add accessibility test for associated label announcement. JIRA: BGSOFUIPIRIN-6858 Part of: #10710
1 parent 775fcd8 commit 7a8e541

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/main/cypress/specs/CheckBox.cy.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,24 @@ describe("CheckBox general interaction", () => {
367367
.find("ui5-icon")
368368
.should("have.attr", "name", "tri-state");
369369
});
370+
});
371+
372+
describe("Accessibility", () => {
373+
it("should announce the associated label when CheckBox is focused", () => {
374+
cy.mount(
375+
<>
376+
<label for="cb">Should be the aria-label</label>
377+
<CheckBox id="cb"></CheckBox>
378+
</>
379+
);
380+
381+
cy.get('label[for="cb"]')
382+
.invoke('text')
383+
.then((labelText) => {
384+
cy.get("[ui5-checkbox]")
385+
.shadow()
386+
.find(".ui5-checkbox-root")
387+
.should("have.attr", "aria-label", labelText);
388+
});
389+
});
370390
});

packages/main/src/CheckBox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
77
import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js";
88
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
99
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
10-
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
10+
import { getEffectiveAriaLabelText, getAssociatedLabelForTexts } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
1111
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
1212
import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js";
1313
import type WrappingType from "./types/WrappingType.js";
@@ -400,7 +400,7 @@ class CheckBox extends UI5Element implements IFormInputElement {
400400
}
401401

402402
get ariaLabelText() {
403-
return getEffectiveAriaLabelText(this);
403+
return getEffectiveAriaLabelText(this) || getAssociatedLabelForTexts(this);
404404
}
405405

406406
get classes() {

0 commit comments

Comments
 (0)