From 791ce19b804b8ab7f2185b7036e22d113c1f9803 Mon Sep 17 00:00:00 2001 From: ayush-chauhan233 Date: Fri, 20 Dec 2024 17:03:05 +0530 Subject: [PATCH] [MA-24]: Added aria-live logic to announce suggested results --- .../components/suggestion/suggestion_list.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webapp/channels/src/components/suggestion/suggestion_list.tsx b/webapp/channels/src/components/suggestion/suggestion_list.tsx index b4b6cd4e7f3..b3ff6c8a0bf 100644 --- a/webapp/channels/src/components/suggestion/suggestion_list.tsx +++ b/webapp/channels/src/components/suggestion/suggestion_list.tsx @@ -50,6 +50,7 @@ export default class SuggestionList extends React.PureComponent { currentLabel: string | null; currentItem: any; maxHeight: number; + suggestedResultStatusRef: React.RefObject; constructor(props: Props) { super(props); @@ -60,6 +61,7 @@ export default class SuggestionList extends React.PureComponent { this.currentLabel = ''; this.currentItem = {}; this.maxHeight = 0; + this.suggestedResultStatusRef = React.createRef(); } componentDidMount() { @@ -244,6 +246,7 @@ export default class SuggestionList extends React.PureComponent { } const clonedItems = cloneDeep(this.props.items); + const suggestedResultStatusElement = this.suggestedResultStatusRef.current; const items = []; if (clonedItems.length === 0) { @@ -288,6 +291,14 @@ export default class SuggestionList extends React.PureComponent { />, ); } + if (suggestedResultStatusElement) { + const firstItem = this.props.items[0]; + if (firstItem.type === 'mention.morechannels') { + suggestedResultStatusElement.textContent = `No result for ${this.props.pretext}`; + } else { + suggestedResultStatusElement.textContent = `${this.props.items.length} results available`; + } + } const mainClass = 'suggestion-list suggestion-list--' + this.props.position; const contentClass = 'suggestion-list__content suggestion-list__content--' + this.props.position; @@ -310,6 +321,12 @@ export default class SuggestionList extends React.PureComponent { > {items} +
); }