Skip to content

Commit d9b42bc

Browse files
authored
feat(ui5-checkbox): implement accessibilityInfo getter (#12527)
1 parent cd6da99 commit d9b42bc

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

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

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,90 @@ describe("Accessibility", () => {
387387
.should("have.attr", "aria-label", labelText);
388388
});
389389
});
390-
});
390+
391+
it("should provide correct accessibilityInfo properties", () => {
392+
cy.mount(
393+
<>
394+
<CheckBox
395+
id="accessibilityTestCb"
396+
text="Accessibility Test"
397+
required
398+
readonly
399+
accessibleName="Custom Aria Label"
400+
></CheckBox>
401+
</>
402+
);
403+
404+
cy.get("#accessibilityTestCb").then($checkbox => {
405+
const checkbox = $checkbox[0] as CheckBox;
406+
const accInfo = checkbox.accessibilityInfo;
407+
408+
// Description should come from accessibleName property
409+
expect(accInfo.description).to.equal("Custom Aria Label");
410+
411+
expect(accInfo.readonly).to.be.true;
412+
expect(accInfo.required).to.be.true;
413+
expect(accInfo.disabled).to.be.false;
414+
415+
expect(accInfo.role).to.equal("checkbox");
416+
});
417+
});
418+
419+
it("should provide correct accessibilityInfo description from accessibleNameRef", () => {
420+
cy.mount(
421+
<>
422+
<label id="cb-label">Label For Accessibility Test</label>
423+
<CheckBox
424+
id="accessibilityTestCb1"
425+
accessibleNameRef="cb-label"
426+
></CheckBox>
427+
</>
428+
);
429+
430+
cy.get("#accessibilityTestCb1").then($checkbox => {
431+
const checkbox = $checkbox[0] as CheckBox;
432+
const accInfo = checkbox.accessibilityInfo;
433+
434+
// Description should come from associated label
435+
expect(accInfo.description).to.equal("Label For Accessibility Test");
436+
});
437+
});
438+
439+
it("should provide correct accessibilityInfo description from text", () => {
440+
cy.mount(
441+
<>
442+
<CheckBox
443+
id="accessibilityTestCb2"
444+
text="Accessibility Test Text"
445+
></CheckBox>
446+
</>
447+
);
448+
449+
cy.get("#accessibilityTestCb2").then($checkbox => {
450+
const checkbox = $checkbox[0] as CheckBox;
451+
const accInfo = checkbox.accessibilityInfo;
452+
453+
// Description should come from text property
454+
expect(accInfo.description).to.equal("Accessibility Test Text");
455+
});
456+
});
457+
458+
it("should provide correct accessibilityInfo description from associated label", () => {
459+
cy.mount(
460+
<>
461+
<label for="accessibilityTestCb3">Label For Accessibility Test</label>
462+
<CheckBox
463+
id="accessibilityTestCb3"
464+
></CheckBox>
465+
</>
466+
);
467+
468+
cy.get("#accessibilityTestCb3").then($checkbox => {
469+
const checkbox = $checkbox[0] as CheckBox;
470+
const accInfo = checkbox.accessibilityInfo;
471+
472+
// Description should come from associated label
473+
expect(accInfo.description).to.equal("Label For Accessibility Test");
474+
});
475+
});
476+
});

packages/main/src/CheckBox.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,16 @@ class CheckBox extends UI5Element implements IFormInputElement {
465465
return this.displayOnly && !this.disabled;
466466
}
467467

468+
get accessibilityInfo() {
469+
return {
470+
role: this.accInfo.role,
471+
description: this.ariaLabelText || this.text || "",
472+
disabled: !!this.accInfo.ariaDisabled,
473+
readonly: !!this.accInfo.ariaReadonly,
474+
required: this.accInfo.ariaRequired,
475+
};
476+
}
477+
468478
get accInfo() {
469479
return {
470480
"role": this._accInfo ? this._accInfo.role : "checkbox" as AriaRole,

0 commit comments

Comments
 (0)