Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/main/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
focused: boolean;
additionalText?: string;
items?: IInputSuggestionItem[];
accessibleDescription?: string;
accessibleDescriptionRef?: string;
}

interface IInputSuggestionItemSelectable extends IInputSuggestionItem {
Expand Down Expand Up @@ -1616,6 +1618,7 @@
onItemSelect(item: IInputSuggestionItem) {
this.valueBeforeItemSelection = this.value;
this.updateValueOnSelect(item);
this.announceSelectedItemAccDescription();
this.announceSelectedItem();

this.fireSelectionChange(item, true);
Expand Down Expand Up @@ -1657,6 +1660,14 @@
}
}

announceSelectedItemAccDescription() {
const invisibleText = this.shadowRoot!.querySelector(`#selectionAccDescription`)!;

if (invisibleText) {
invisibleText.textContent = this.suggestionAdditionalAccText;
}
}

fireSelectionChange(item: IInputSuggestionItem | null, isValueFromSuggestions: boolean) {
if (this.Suggestions) {
this.fireDecoratorEvent(INPUT_EVENTS.SELECTION_CHANGE, { item });
Expand Down Expand Up @@ -1897,6 +1908,23 @@
return Input.i18nBundle.getText(INPUT_SUGGESTIONS);
}

get suggestionAdditionalAccText() {
if (!this.Suggestions || !this.Suggestions?._getItems().length) return "";

Check failure on line 1912 in packages/main/src/Input.ts

View workflow job for this annotation

GitHub Actions / check

Expected { after 'if' condition

const selectedItem = this.Suggestions?._getItems()[this.Suggestions?.selectedItemIndex];

if (!selectedItem) {
return "";
}

if (!selectedItem.accessibleDescriptionRef) {
return selectedItem.accessibleDescription ? selectedItem.accessibleDescription : "";
}

const text = selectedItem.querySelector(`#${selectedItem.accessibleDescriptionRef}`);
return text ? text.textContent || "" : "";
}

get availableSuggestionsCount() {
if (this.showSuggestions && (this.value || this.Suggestions?.isOpened())) {
const nonGroupItems = this._selectableItems;
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/InputTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default function InputTemplate(this: Input, hooks?: { preContent: Templat

{this._effectiveShowSuggestions &&
<>
<span id="selectionAccDescription" class="ui5-hidden-text" aria-live="polite" role="status"></span>
<span id="suggestionsText" class="ui5-hidden-text">{this.suggestionsText}</span>
<span id="selectionText" class="ui5-hidden-text" aria-live="polite" role="status"></span>
<span id="suggestionsCount" class="ui5-hidden-text" aria-live="polite">{this.availableSuggestionsCount}</span>
Expand Down
16 changes: 16 additions & 0 deletions packages/main/src/SuggestionItemCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ class SuggestionItemCustom extends ListItemBase implements IInputSuggestionItemS
@property()
text?: string;

/**
* Defines the accessible description of the component.
* @default undefined
* @public
*/
@property()
accessibleDescription?: string;

/**
* Defines the IDs of the elements that describe the component.
* @default undefined
* @public
*/
@property()
accessibleDescriptionRef?: string;

/**
* Defines the content of the component.
*
Expand Down
28 changes: 20 additions & 8 deletions packages/main/test/pages/MultiInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,29 @@ <h1 class="sample-container-title">Eventing</h1>
<h1 class="sample-container-title">Custom Suggestions</h1>

<ui5-multi-input id="mi-custom-suggestions" show-suggestions>
<ui5-suggestion-item-custom text="Bulgaria">
<span>Bulgaria</span>
<ui5-suggestion-item-custom text="Bulgaria" accessible-description-ref="custom-1">
<div >
<span>Bulgaria</span>
<span id="custom-1">BG</span>
</div>
</ui5-suggestion-item-custom>
<ui5-suggestion-item-custom text="Germany">
<span>Germany</span>
<ui5-suggestion-item-custom text="Germany" accessible-description="GE">
<div>
<span>Germany</span>
<span>DE</span>
</div>
</ui5-suggestion-item-custom>
<ui5-suggestion-item-custom text="USA">
<span>USA</span>
<ui5-suggestion-item-custom text="USA" accessible-description="Some random text that will not be read" accessible-description-ref="custom-3">
<div>
<span>USA</span>
<span id="custom-3">US - ref</span>
</div>
</ui5-suggestion-item-custom>
<ui5-suggestion-item-custom text="Romania">
<span>Romania</span>
<ui5-suggestion-item-custom text="Romania" accessible-description-ref="custom-4">
<div id="custom-4">
<span>Romania</span>
<span>RO</span>
</div>
</ui5-suggestion-item-custom>
</ui5-multi-input>
</div>
Expand Down
Loading