Improve VoiceOver & WebKit accessibility support

Based on https://bugs.webkit.org/show_bug.cgi?id=167671#c15
(workaround)
This commit is contained in:
Michael Telatynski 2021-02-18 10:55:24 +00:00
parent 9e2974d84d
commit 9463fda1c1
9 changed files with 14 additions and 21 deletions

View file

@ -27,11 +27,11 @@ export interface ICommand {
}; };
} }
export default class AutocompleteProvider { export default abstract class AutocompleteProvider {
commandRegex: RegExp; commandRegex: RegExp;
forcedCommandRegex: RegExp; forcedCommandRegex: RegExp;
constructor(commandRegex?: RegExp, forcedCommandRegex?: RegExp) { protected constructor(commandRegex?: RegExp, forcedCommandRegex?: RegExp) {
if (commandRegex) { if (commandRegex) {
if (!commandRegex.global) { if (!commandRegex.global) {
throw new Error('commandRegex must have global flag set'); throw new Error('commandRegex must have global flag set');
@ -93,18 +93,11 @@ export default class AutocompleteProvider {
}; };
} }
async getCompletions(query: string, selection: ISelectionRange, force = false): Promise<ICompletion[]> { abstract getCompletions(query: string, selection: ISelectionRange, force: boolean): Promise<ICompletion[]>;
return [];
}
getName(): string { abstract getName(): string;
return 'Default Provider';
}
renderCompletions(completions: React.ReactNode[]): React.ReactNode | null { abstract renderCompletions(completions: React.ReactNode[]): React.ReactNode | null;
console.error('stub; should be implemented in subclasses');
return null;
}
// Whether we should provide completions even if triggered forcefully, without a sigil. // Whether we should provide completions even if triggered forcefully, without a sigil.
shouldForceComplete(): boolean { shouldForceComplete(): boolean {

View file

@ -91,7 +91,7 @@ export default class CommandProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_block" className="mx_Autocomplete_Completion_container_block"
role="listbox" role="presentation"
aria-label={_t("Command Autocomplete")} aria-label={_t("Command Autocomplete")}
> >
{ completions } { completions }

View file

@ -112,7 +112,7 @@ export default class CommunityProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate" className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate"
role="listbox" role="presentation"
aria-label={_t("Community Autocomplete")} aria-label={_t("Community Autocomplete")}
> >
{ completions } { completions }

View file

@ -99,7 +99,7 @@ export default class DuckDuckGoProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_block" className="mx_Autocomplete_Completion_container_block"
role="listbox" role="presentation"
aria-label={_t("DuckDuckGo Results")} aria-label={_t("DuckDuckGo Results")}
> >
{ completions } { completions }

View file

@ -140,7 +140,7 @@ export default class EmojiProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_pill" className="mx_Autocomplete_Completion_container_pill"
role="listbox" role="presentation"
aria-label={_t("Emoji Autocomplete")} aria-label={_t("Emoji Autocomplete")}
> >
{ completions } { completions }

View file

@ -66,7 +66,7 @@ export default class NotifProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate" className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate"
role="listbox" role="presentation"
aria-label={_t("Notification Autocomplete")} aria-label={_t("Notification Autocomplete")}
> >
{ completions } { completions }

View file

@ -123,7 +123,7 @@ export default class RoomProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate" className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate"
role="listbox" role="presentation"
aria-label={_t("Room Autocomplete")} aria-label={_t("Room Autocomplete")}
> >
{ completions } { completions }

View file

@ -178,7 +178,7 @@ export default class UserProvider extends AutocompleteProvider {
return ( return (
<div <div
className="mx_Autocomplete_Completion_container_pill" className="mx_Autocomplete_Completion_container_pill"
role="listbox" role="presentation"
aria-label={_t("User Autocomplete")} aria-label={_t("User Autocomplete")}
> >
{ completions } { completions }

View file

@ -298,7 +298,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
return completions.length > 0 ? ( return completions.length > 0 ? (
<div key={i} className="mx_Autocomplete_ProviderSection"> <div key={i} className="mx_Autocomplete_ProviderSection" role="presentation">
<div className="mx_Autocomplete_provider_name">{ completionResult.provider.getName() }</div> <div className="mx_Autocomplete_provider_name">{ completionResult.provider.getName() }</div>
{ completionResult.provider.renderCompletions(completions) } { completionResult.provider.renderCompletions(completions) }
</div> </div>
@ -306,7 +306,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
}).filter((completion) => !!completion); }).filter((completion) => !!completion);
return !this.state.hide && renderedCompletions.length > 0 ? ( return !this.state.hide && renderedCompletions.length > 0 ? (
<div className="mx_Autocomplete" ref={this.containerRef}> <div id="mx_Autocomplete" className="mx_Autocomplete" ref={this.containerRef} role="listbox">
{ renderedCompletions } { renderedCompletions }
</div> </div>
) : null; ) : null;