Skip to content

Commit 3afc0e8

Browse files
authored
feat(ui5-select): implement accessibilityInfo getter (#12614)
* feat(ui5-select): implement accessibilityInfo getter * chore: fix lint errors * chore: make type translatable and add missing disabled property * chore: remove aria label from description and return it as label property
1 parent 4c63fdc commit 3afc0e8

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,85 @@ describe("Select - Accessibility", () => {
513513
.find(".ui5-select-label-root")
514514
.should("contain.text", "SelectedOption – ExtraInfo");
515515
});
516+
517+
it("tests accessibilityInfo getter returns correct values", () => {
518+
cy.mount(
519+
<>
520+
<span id="labelRef">Reference Label</span>
521+
{/* Basic select with selected option */}
522+
<Select id="basicSelect">
523+
<Option value="Option1" selected>Option 1</Option>
524+
<Option value="Option2">Option 2</Option>
525+
</Select>
526+
527+
{/* Select with accessibleName */}
528+
<Select id="namedSelect" accessibleName="Select Name">
529+
<Option value="Option1" selected>Option 1</Option>
530+
</Select>
531+
532+
{/* Select with accessibleNameRef */}
533+
<Select id="refSelect" accessibleNameRef="labelRef">
534+
<Option value="Option1" selected>Option 1</Option>
535+
</Select>
536+
537+
{/* Select with readonly and required attributes */}
538+
<Select id="propsSelect" readonly required disabled>
539+
<Option value="Option1" selected>Option 1</Option>
540+
</Select>
541+
</>
542+
);
543+
544+
// Test basic select
545+
cy.get("#basicSelect").then(($select) => {
546+
const select = $select[0] as Select;
547+
const accessInfo = select.accessibilityInfo;
548+
549+
expect(accessInfo.role).to.equal("combobox");
550+
expect(accessInfo.type).to.equal("Listbox");
551+
expect(accessInfo.readonly).to.be.false;
552+
expect(accessInfo.required).to.be.false;
553+
expect(accessInfo.description).to.equal("Option 1"); // Just text
554+
expect(accessInfo.label).to.be.undefined; // No aria-label
555+
});
556+
557+
// Test select with accessibleName
558+
cy.get("#namedSelect").then(($select) => {
559+
const select = $select[0] as Select;
560+
const accessInfo = select.accessibilityInfo;
561+
562+
expect(accessInfo.description).to.equal("Option 1"); // Just text
563+
expect(accessInfo.label).to.equal("Select Name"); // Aria label
564+
});
565+
566+
// Test select with accessibleNameRef
567+
cy.get("#refSelect").then(($select) => {
568+
const select = $select[0] as Select;
569+
const accessInfo = select.accessibilityInfo;
570+
571+
expect(accessInfo.description).to.equal("Option 1"); // Just text
572+
expect(accessInfo.label).to.equal("Reference Label"); // Aria label from ref
573+
});
574+
575+
// Test select with readonly and required properties
576+
cy.get("#propsSelect").then(($select) => {
577+
const select = $select[0] as Select;
578+
const accessInfo = select.accessibilityInfo;
579+
580+
expect(accessInfo.readonly).to.be.true;
581+
expect(accessInfo.required).to.be.true;
582+
expect(accessInfo.disabled).to.be.true;
583+
});
584+
585+
// Update the referenced label and check if the label updates
586+
cy.get("#labelRef").invoke("text", "Updated Reference");
587+
cy.get("#refSelect").then(($select) => {
588+
const select = $select[0] as Select;
589+
const accessInfo = select.accessibilityInfo;
590+
591+
expect(accessInfo.description).to.equal("Option 1"); // Text remains the same
592+
expect(accessInfo.label).to.equal("Updated Reference"); // Updated aria label from ref
593+
});
594+
});
516595
});
517596

518597
describe("Select - Popover", () => {
@@ -1740,4 +1819,4 @@ describe("Select general interaction", () => {
17401819
.should("have.attr", "selected");
17411820
cy.get("[ui5-select]").should("have.prop", "value", "C");
17421821
});
1743-
});
1822+
});

packages/main/src/Select.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import "@ui5/webcomponents-icons/dist/information.js";
3434
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
3535
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
3636
import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js";
37-
import type { Timeout } from "@ui5/webcomponents-base/dist/types.js";
37+
import type { Timeout, AriaRole } from "@ui5/webcomponents-base/dist/types.js";
3838
import InvisibleMessageMode from "@ui5/webcomponents-base/dist/types/InvisibleMessageMode.js";
3939
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
4040
import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js";
@@ -1174,6 +1174,18 @@ class Select extends UI5Element implements IFormInputElement {
11741174
return ids.length ? ids.join(" ") : undefined;
11751175
}
11761176

1177+
get accessibilityInfo() {
1178+
return {
1179+
role: "combobox" as AriaRole,
1180+
type: this._ariaRoleDescription,
1181+
description: this.text,
1182+
label: this.ariaLabelText,
1183+
readonly: this.readonly,
1184+
required: this.required,
1185+
disabled: this.disabled,
1186+
};
1187+
}
1188+
11771189
_updateAssociatedLabelsTexts() {
11781190
this._associatedDescriptionRefTexts = getAllAccessibleDescriptionRefTexts(this);
11791191
}

0 commit comments

Comments
 (0)