Skip to content

Commit 6df8a30

Browse files
feat(ui5-combobox/ui5-multi-combobox): enable for attribute support (SAP#11453)
1 parent 3a56fd3 commit 6df8a30

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,31 @@ describe("Event firing", () => {
168168
cy.get("@changeStub").should("not.have.been.called");
169169
});
170170
});
171+
describe("Accessibility", () => {
172+
it("should announce the associated label when ComboBox is focused", () => {
173+
cy.mount(
174+
<>
175+
<label for="cb">Should be the aria-label</label>
176+
<ComboBox id="cb"/>
177+
</>
178+
);
179+
180+
cy.get('label[for="cb"]')
181+
.invoke('text')
182+
.then((labelText) => {
183+
184+
cy.get("[ui5-combobox]")
185+
.shadow()
186+
.find("input")
187+
.as("innerInput");
188+
189+
cy.get("@innerInput")
190+
.click();
191+
192+
cy.get("@innerInput")
193+
.should("have.attr", "aria-label", labelText);
194+
});
195+
});
196+
});
197+
171198

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,30 @@ describe("Event firing", () => {
160160
.should("have.been.calledTwice");
161161
});
162162
});
163+
164+
describe("Accessibility", () => {
165+
it("should announce the associated label when MultiComboBox is focused", () => {
166+
cy.mount(
167+
<>
168+
<label for="mcb">MultiComboBox aria-label</label>
169+
<MultiComboBox id="mcb"></MultiComboBox>
170+
</>
171+
);
172+
173+
cy.get('label[for="mcb"]')
174+
.invoke('text')
175+
.then((labelText) => {
176+
177+
cy.get("[ui5-multi-combobox]")
178+
.shadow()
179+
.find("input")
180+
.as("innerInput");
181+
182+
cy.get("@innerInput")
183+
.click();
184+
185+
cy.get("@innerInput")
186+
.should("have.attr", "aria-label", labelText);
187+
});
188+
});
189+
});

packages/main/src/ComboBox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
77
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
88
import { isPhone, isAndroid } from "@ui5/webcomponents-base/dist/Device.js";
99
import InvisibleMessageMode from "@ui5/webcomponents-base/dist/types/InvisibleMessageMode.js";
10-
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
10+
import { getEffectiveAriaLabelText, getAssociatedLabelForTexts } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
1111
import announce from "@ui5/webcomponents-base/dist/util/InvisibleMessage.js";
1212
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
1313
import "@ui5/webcomponents-icons/dist/slim-arrow-down.js";
@@ -1351,7 +1351,7 @@ class ComboBox extends UI5Element implements IFormInputElement {
13511351
}
13521352

13531353
get ariaLabelText(): string | undefined {
1354-
return getEffectiveAriaLabelText(this);
1354+
return getEffectiveAriaLabelText(this) || getAssociatedLabelForTexts(this);
13551355
}
13561356

13571357
get clearIconAccessibleName() {

packages/main/src/MultiComboBox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import "@ui5/webcomponents-icons/dist/error.js";
4949
import "@ui5/webcomponents-icons/dist/alert.js";
5050
import "@ui5/webcomponents-icons/dist/sys-enter-2.js";
5151
import "@ui5/webcomponents-icons/dist/information.js";
52-
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
52+
import { getAssociatedLabelForTexts, getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
5353
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
5454
import { submitForm } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js";
5555
import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js";
@@ -1868,7 +1868,7 @@ class MultiComboBox extends UI5Element implements IFormInputElement {
18681868
}
18691869

18701870
get ariaLabelText() {
1871-
return getEffectiveAriaLabelText(this);
1871+
return getEffectiveAriaLabelText(this) || getAssociatedLabelForTexts(this);
18721872
}
18731873

18741874
/**

0 commit comments

Comments
 (0)