Skip to content

Commit c4213a0

Browse files
committed
feat(ui5-checkbox): implement accessibilityInfo getter
1 parent 12f391f commit c4213a0

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

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

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,93 @@ 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+
expect(accInfo.type).to.equal("checkbox");
409+
410+
// Description should come from accessibleName property
411+
expect(accInfo.description).to.equal("Custom Aria Label");
412+
413+
expect(accInfo.readonly).to.be.true;
414+
expect(accInfo.required).to.be.true;
415+
expect(accInfo.disabled).to.be.false;
416+
417+
expect(accInfo.role).to.equal("checkbox");
418+
});
419+
});
420+
421+
// should provide correct accessibilityInfo description from associated label wits accessibleNameRef
422+
it("should provide correct accessibilityInfo description from accessibleNameRef", () => {
423+
cy.mount(
424+
<>
425+
<label id="cb-label">Label For Accessibility Test</label>
426+
<CheckBox
427+
id="accessibilityTestCb1"
428+
accessibleNameRef="cb-label"
429+
></CheckBox>
430+
</>
431+
);
432+
433+
cy.get("#accessibilityTestCb1").then($checkbox => {
434+
const checkbox = $checkbox[0] as CheckBox;
435+
const accInfo = checkbox.accessibilityInfo;
436+
437+
// Description should come from associated label
438+
expect(accInfo.description).to.equal("Label For Accessibility Test");
439+
});
440+
});
441+
442+
it("should provide correct accessibilityInfo description from text", () => {
443+
cy.mount(
444+
<>
445+
<CheckBox
446+
id="accessibilityTestCb2"
447+
text="Accessibility Test Text"
448+
></CheckBox>
449+
</>
450+
);
451+
452+
cy.get("#accessibilityTestCb2").then($checkbox => {
453+
const checkbox = $checkbox[0] as CheckBox;
454+
const accInfo = checkbox.accessibilityInfo;
455+
456+
// Description should come from text property
457+
expect(accInfo.description).to.equal("Accessibility Test Text");
458+
});
459+
});
460+
461+
it("should provide correct accessibilityInfo description from associated label", () => {
462+
cy.mount(
463+
<>
464+
<label for="accessibilityTestCb3">Label For Accessibility Test</label>
465+
<CheckBox
466+
id="accessibilityTestCb3"
467+
></CheckBox>
468+
</>
469+
);
470+
471+
cy.get("#accessibilityTestCb3").then($checkbox => {
472+
const checkbox = $checkbox[0] as CheckBox;
473+
const accInfo = checkbox.accessibilityInfo;
474+
475+
// Description should come from associated label
476+
expect(accInfo.description).to.equal("Label For Accessibility Test");
477+
});
478+
});
479+
});

packages/main/src/CheckBox.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
VALUE_STATE_WARNING,
2323
VALUE_STATE_SUCCESS,
2424
FORM_CHECKABLE_REQUIRED,
25+
CHECKBOX_ARIA_TYPE,
2526
} from "./generated/i18n/i18n-defaults.js";
2627

2728
// Styles
@@ -465,6 +466,17 @@ class CheckBox extends UI5Element implements IFormInputElement {
465466
return this.displayOnly && !this.disabled;
466467
}
467468

469+
get accessibilityInfo() {
470+
return {
471+
role: this.accInfo.role,
472+
type: CheckBox.i18nBundle.getText(CHECKBOX_ARIA_TYPE),
473+
description: this.ariaLabelText || this.text || "",
474+
disabled: !!this.accInfo.ariaDisabled,
475+
readonly: !!this.accInfo.ariaReadonly,
476+
required: this.accInfo.ariaRequired,
477+
};
478+
}
479+
468480
get accInfo() {
469481
return {
470482
"role": this._accInfo ? this._accInfo.role : "checkbox" as AriaRole,

packages/main/src/i18n/messagebundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ BREADCRUMB_ITEM_POS={0} of {1}
5555
#XACT: ARIA announcement for the breadcrumbs
5656
BREADCRUMBS_ARIA_LABEL=Breadcrumb Trail
5757

58+
#XACT: ARIA announcement for the CheckBox component type
59+
CHECKBOX_ARIA_TYPE=checkbox
60+
5861
#XACT: ARIA announcement for the breadcrumbs overflow button
5962
BREADCRUMBS_OVERFLOW_ARIA_LABEL=More
6063

0 commit comments

Comments
 (0)