Skip to content

Commit 4c63fdc

Browse files
authored
fix(ui5-checkbox): fix accessibilityInfo (#12686)
* fix(ui5-checkbox): fix accessibilityInfo * chore: fix lint errors * chore: remove custom label from description, instead - return it as label
1 parent 23a2df8 commit 4c63fdc

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,14 @@ describe("Accessibility", () => {
406406
const accInfo = checkbox.accessibilityInfo;
407407

408408
// Description should come from accessibleName property
409-
expect(accInfo.description).to.equal("Custom Aria Label");
409+
expect(accInfo.description).to.equal("Accessibility Test Not checked");
410+
expect(accInfo.label).to.equal("Custom Aria Label");
410411

411412
expect(accInfo.readonly).to.be.true;
412413
expect(accInfo.required).to.be.true;
413414
expect(accInfo.disabled).to.be.false;
414-
415+
416+
expect(accInfo.type).to.equal("Checkbox");
415417
expect(accInfo.role).to.equal("checkbox");
416418
});
417419
});
@@ -432,26 +434,8 @@ describe("Accessibility", () => {
432434
const accInfo = checkbox.accessibilityInfo;
433435

434436
// 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");
437+
expect(accInfo.description).to.equal("Not checked");
438+
expect(accInfo.label).to.equal("Label For Accessibility Test");
455439
});
456440
});
457441

@@ -470,7 +454,8 @@ describe("Accessibility", () => {
470454
const accInfo = checkbox.accessibilityInfo;
471455

472456
// Description should come from associated label
473-
expect(accInfo.description).to.equal("Label For Accessibility Test");
457+
expect(accInfo.description).to.equal("Not checked");
458+
expect(accInfo.label).to.equal("Label For Accessibility Test");
474459
});
475460
});
476461
});

packages/main/src/CheckBox.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import {
2222
VALUE_STATE_WARNING,
2323
VALUE_STATE_SUCCESS,
2424
FORM_CHECKABLE_REQUIRED,
25+
CHECKBOX_CHECKED,
26+
CHECKBOX_NOT_CHECKED,
27+
CHECKBOX_ARIA_TYPE,
2528
} from "./generated/i18n/i18n-defaults.js";
2629

2730
// Styles
@@ -466,9 +469,14 @@ class CheckBox extends UI5Element implements IFormInputElement {
466469
}
467470

468471
get accessibilityInfo() {
472+
const checkboxState = this.checked ? CheckBox.i18nBundle.getText(CHECKBOX_CHECKED) : CheckBox.i18nBundle.getText(CHECKBOX_NOT_CHECKED);
473+
const description = [this.text || "", checkboxState].filter(Boolean).join(" ");
474+
469475
return {
470476
role: this.accInfo.role,
471-
description: this.ariaLabelText || this.text || "",
477+
type: CheckBox.i18nBundle.getText(CHECKBOX_ARIA_TYPE),
478+
description,
479+
label: this.ariaLabelText,
472480
disabled: !!this.accInfo.ariaDisabled,
473481
readonly: !!this.accInfo.ariaReadonly,
474482
required: this.accInfo.ariaRequired,

packages/main/src/i18n/messagebundle.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,15 @@ DYNAMIC_DATE_RANGE_LAST_YEARS_TEXT=Last X Years
922922
#XFLD: Text for the "Next Years" option in the DynamicDateRange component.
923923
DYNAMIC_DATE_RANGE_NEXT_YEARS_TEXT=Next X Years
924924

925+
#XACT: Text for checkbox state - checked
926+
CHECKBOX_CHECKED=Checked
927+
928+
#XACT: Text for checkbox state - not checked
929+
CHECKBOX_NOT_CHECKED=Not checked
930+
931+
#XACT: ARIA type for checkbox
932+
CHECKBOX_ARIA_TYPE=Checkbox
933+
925934
#XFLD: Label for the value input field in the DynamicDateRange component.
926935
DYNAMIC_DATE_RANGE_VALUE_LABEL_TEXT=Value for X
927936

0 commit comments

Comments
 (0)