Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MA-24]: Added aria-live logic to announce suggested results #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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'
/>
</div>
);
}
Expand Down
Loading