Skip to content

Commit ef0441e

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

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,28 @@ describe("Select - Accessibility", () => {
203203
cy.get("@select")
204204
.should("have.attr", "title", "Go home");
205205
});
206+
207+
it("should announce the associated label when Select is focused", () => {
208+
cy.mount(
209+
<>
210+
<label for="sel">Should be the aria-label</label>
211+
<Select id="sel">
212+
<Option value="option1">Option 1</Option>
213+
<Option value="option2">Option 2</Option>
214+
<Option value="option3">Option 3</Option>
215+
</Select>
216+
</>
217+
);
218+
219+
cy.get('label[for="sel"]')
220+
.invoke('text')
221+
.then((labelText) => {
222+
cy.get("[ui5-select]")
223+
.shadow()
224+
.find(".ui5-select-label-root")
225+
.should("have.attr", "aria-label", labelText);
226+
});
227+
});
206228
});
207229

208230
describe("Select - Popover", () => {

packages/main/src/Select.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
isTabPrevious,
1818
} from "@ui5/webcomponents-base/dist/Keys.js";
1919
import announce from "@ui5/webcomponents-base/dist/util/InvisibleMessage.js";
20-
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
20+
import { getEffectiveAriaLabelText, getAssociatedLabelForTexts } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
2121
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
2222
import "@ui5/webcomponents-icons/dist/error.js";
2323
import "@ui5/webcomponents-icons/dist/alert.js";
@@ -966,7 +966,7 @@ class Select extends UI5Element implements IFormInputElement {
966966
}
967967

968968
get ariaLabelText() {
969-
return getEffectiveAriaLabelText(this);
969+
return getEffectiveAriaLabelText(this) || getAssociatedLabelForTexts(this);
970970
}
971971

972972
get shouldDisplayDefaultValueStateMessage() {

0 commit comments

Comments
 (0)