Skip to content

Commit bdc746a

Browse files
fix(ui5-multi-input): announce value help (#11221)
1 parent dc8ff89 commit bdc746a

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SuggestionItem from "../../src/SuggestionItem.js";
22
import MultiInput from "../../src/MultiInput.js";
33
import "../../src/Token.js";
4+
import { MULTIINPUT_VALUE_HELP } from "../../src/generated/i18n/i18n-defaults.js";
45

56
describe("MultiInput Web Component", () => {
67
it("creates only one token when typing 'ad' and pressing Enter", () => {
@@ -48,4 +49,24 @@ describe("MultiInput Web Component", () => {
4849
.should("have.length", 1)
4950
.and("have.attr", "text", "ad");
5051
});
52+
53+
it("Value Help announcement", () => {
54+
const valueHelpId = "hiddenText-value-help";
55+
56+
cy.mount(<MultiInput showValueHelpIcon={true}></MultiInput>);
57+
58+
cy.get("[ui5-multi-input]")
59+
.as("multiInput");
60+
61+
cy.get("@multiInput")
62+
.shadow()
63+
.find("input")
64+
.should("have.attr", "aria-describedby")
65+
.and("include", valueHelpId);
66+
67+
cy.get("@multiInput")
68+
.shadow()
69+
.find(`#${valueHelpId}`)
70+
.should("have.text", MULTIINPUT_VALUE_HELP.defaultText);
71+
});
5172
});

packages/main/src/MultiInput.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import type { ITabbable } from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
1818
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
1919
import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js";
20-
import { MULTIINPUT_ROLEDESCRIPTION_TEXT, MULTIINPUT_VALUE_HELP_LABEL } from "./generated/i18n/i18n-defaults.js";
20+
import { MULTIINPUT_ROLEDESCRIPTION_TEXT, MULTIINPUT_VALUE_HELP_LABEL, MULTIINPUT_VALUE_HELP } from "./generated/i18n/i18n-defaults.js";
2121
import Input from "./Input.js";
2222
import MultiInputTemplate from "./MultiInputTemplate.js";
2323
import styles from "./generated/themes/MultiInput.css.js";
@@ -364,10 +364,18 @@ class MultiInput extends Input implements IFormInputElement {
364364
return getTokensCountText(this.tokens.length);
365365
}
366366

367+
get _valueHelpText() {
368+
return MultiInput.i18nBundle.getText(MULTIINPUT_VALUE_HELP);
369+
}
370+
367371
get _tokensCountTextId() {
368372
return `hiddenText-nMore`;
369373
}
370374

375+
get _valueHelpTextId() {
376+
return this.showValueHelpIcon ? `hiddenText-value-help` : "";
377+
}
378+
371379
/**
372380
* Returns the placeholder value when there are no tokens.
373381
* @protected
@@ -381,7 +389,7 @@ class MultiInput extends Input implements IFormInputElement {
381389
}
382390

383391
get accInfo() {
384-
const ariaDescribedBy = `${this._tokensCountTextId} ${this.suggestionsTextId} ${this.valueStateTextId}`.trim();
392+
const ariaDescribedBy = `${this._tokensCountTextId} ${this.suggestionsTextId} ${this.valueStateTextId} ${this._valueHelpTextId}`.trim();
385393
return {
386394
...super.accInfo,
387395
"ariaRoledescription": this.ariaRoleDescription,

packages/main/src/MultiInputTemplate.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function preContent(this: MultiInput) {
1414
return (
1515
<>
1616
<span id="hiddenText-nMore" class="ui5-hidden-text">{this._tokensCountText}</span>
17+
18+
{this.showValueHelpIcon &&
19+
<span id="hiddenText-value-help" class="ui5-hidden-text">{this._valueHelpText}</span>
20+
}
1721
<Tokenizer
1822
class="ui5-multi-input-tokenizer"
1923
opener={this.morePopoverOpener}

packages/main/src/i18n/messagebundle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,12 @@ MULTIINPUT_ROLEDESCRIPTION_TEXT=Multi Value Input
336336
#XFLD: Token number indicator which is used to show more tokens
337337
MULTIINPUT_SHOW_MORE_TOKENS={0} more
338338

339-
#XACT: ARIA announcement for value help
339+
#XACT: ARIA announcement for value help icon
340340
MULTIINPUT_VALUE_HELP_LABEL=Show Value Help
341341

342+
#XACT: ARIA announcement for value help
343+
MULTIINPUT_VALUE_HELP=Value help available
344+
342345
#XTOL: Tooltip for panel expand title
343346
PANEL_ICON=Expand/Collapse
344347

packages/main/test/specs/MultiInput.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,19 @@ describe("ARIA attributes", () => {
396396
const innerInput = await mi.shadow$("input");
397397
const tokensCountITextId = `hiddenText-nMore`;
398398
const suggestionsITextId = `suggestionsText`;
399-
const ariaDescribedBy = `${tokensCountITextId} ${suggestionsITextId}`;
399+
const valueHelpTextId = "hiddenText-value-help";
400400

401401
await browser.$("#suggestion-token").scrollIntoView();
402402
await innerInput.click();
403403
await innerInput.keys("a");
404404
await innerInput.keys("ArrowDown");
405405
await innerInput.keys("Enter");
406406

407-
assert.strictEqual(await innerInput.getAttribute("aria-describedby"), ariaDescribedBy, "aria-describedby attribute contains multiple references");
407+
const ariaDescribedBy = await innerInput.getAttribute("aria-describedby");
408+
409+
assert.ok(ariaDescribedBy.includes(tokensCountITextId), "aria-describedby should contain tokens count");
410+
assert.ok(ariaDescribedBy.includes(suggestionsITextId), "aria-describedby should contain suggestions announcement when suggestions are enabled");
411+
assert.ok(ariaDescribedBy.includes(valueHelpTextId), "aria-describedby should contain value help announcement when value help is enabled");
408412
});
409413

410414
it("aria-roledescription is set properly", async () => {

0 commit comments

Comments
 (0)