Skip to content

Commit

Permalink
[MA-24]: Added aria-live logic to announce suggested results
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-chauhan233 committed Dec 20, 2024
1 parent 76a3af6 commit e6c93cb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions webapp/channels/src/components/suggestion/suggestion_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class SuggestionList extends React.PureComponent<Props> {
currentLabel: string | null;
currentItem: any;
maxHeight: number;
suggestedResultStatusRef: React.RefObject<HTMLDivElement>;

constructor(props: Props) {
super(props);
Expand All @@ -60,6 +61,7 @@ export default class SuggestionList extends React.PureComponent<Props> {
this.currentLabel = '';
this.currentItem = {};
this.maxHeight = 0;
this.suggestedResultStatusRef = React.createRef();
}

componentDidMount() {
Expand Down Expand Up @@ -244,6 +246,7 @@ export default class SuggestionList extends React.PureComponent<Props> {
}

const clonedItems = cloneDeep(this.props.items);
const suggestedResultStatusElement = this.suggestedResultStatusRef.current;

const items = [];
if (clonedItems.length === 0) {
Expand Down Expand Up @@ -288,6 +291,14 @@ export default class SuggestionList extends React.PureComponent<Props> {
/>,
);
}
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;

Expand All @@ -310,6 +321,12 @@ export default class SuggestionList extends React.PureComponent<Props> {
>
{items}
</div>
<div
ref={this.suggestedResultStatusRef}
aria-live='polite'
role='status'
className='sr-only something-new'
/>
</div>
);
}
Expand Down

0 comments on commit e6c93cb

Please sign in to comment.