Accessibility in React Auto complete component

24 Jan 202418 minutes to read

The AutoComplete component has been designed, keeping in mind the WAI-ARIA specifications, and applies the WAI-ARIA roles, states, and properties along with keyboard support. This component is characterized by complete keyboard interaction support and ARIA accessibility support that makes it easy for people who use assistive technologies(AT) or those who completely rely on keyboard navigation.

The AutoComplete component followed the accessibility guidelines and standards, including ADA, Section 508, WCAG 2.2 standards, and WCAG roles that are commonly used to evaluate accessibility.

The accessibility compliance for the AutoComplete component is outlined below.

Accessibility Criteria Compatibility
WCAG 2.2 Support Intermediate
Section 508 Support Intermediate
Screen Reader Support Yes
Right-To-Left Support Yes
Color Contrast Yes
Mobile Device Support Yes
Keyboard Navigation Support Yes
Accessibility Checker Validation Yes
Axe-core Accessibility Validation Yes
Yes - All features of the component meet the requirement.
Intermediate - Some features of the component do not meet the requirement.
No - The component does not meet the requirement.

WAI-ARIA attributes

The AutoComplete component followed the WAI-ARIA patterns to meet the accessibility. The following ARIA attributes are used in the AutoComplete component:

Property Functionalities
aria-haspopup Indicates whether the AutoComplete input element has a suggestion list or not.
aria-expanded Indicates whether the suggestion list has expanded or not.
aria-selected Indicates the selected option from the list.
aria-readonly Indicates the readonly state of the AutoComplete element.
aria-disabled Indicates whether the AutoComplete component is in a disabled state or not.
aria-activedescendent This attribute holds the ID of the active list item to focus its descendant child element.
aria-owns This attribute contains the ID of the suggestion list to indicate popup as a child element.
aria-autocomplete This attribute contains the ‘both’ to a list of options shows and the currently selected suggestion also shows inline.

Keyboard Interaction

You can use the following key shortcuts to access the AutoComplete without interruptions.

Keyboard shortcuts Actions
Arrow Down In popup hidden state, opens the suggestion list. In popup open state, selects the first item when no item selected else selects the item next to the currently selected item.
Arrow Up In popup hidden state, opens the suggestion list. In popup open state, selects the last item when no item selected else selects the item previous to the currently selected one.
Page Down Scrolls down to the next page and selects the first item when popup list opens.
Page Up Scrolls up to previous page and select the first item when popup list open.
Enter Selects the focused item and set to AutoComplete component.
Tab Focuses on the next tab indexed element when the popup is closed. Otherwise, closes the popup list and remains the focus in component suppose if it is in an open state.
Shift + tab Focuses the previous tab indexed element when the popup is closed. Otherwise,closes the popup list and remains the focus in component suppose if it is in an open state.
Alt + Down Opens the popup list.
Alt + Up In popup hidden state, opens the popup list. In popup open state, closes the popup list.
Esc(Escape) Closes the popup list when it is in an open state then remove the selection.
Home Cursor moves to before of first character in input.
End Cursor moves to next of last character in input.

In the below sample, focus the AutoComplete component using alt+t keys.

[Class-component]

import { AutoCompleteComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component {
    // defined the array of data
    gameList = [
        { Id: 'Game1', Game: 'Badminton' },
        { Id: 'Game2', Game: 'Basketball' },
        { Id: 'Game3', Game: 'Cricket' },
        { Id: 'Game4', Game: 'Football' },
        { Id: 'Game5', Game: 'Golf' },
        { Id: 'Game6', Game: 'Hockey' },
        { Id: 'Game7', Game: 'Rugby' },
        { Id: 'Game8', Game: 'Snooker' }
    ];
    // maps the appropriate column to fields property
    fields = { value: 'Game' };
    // instance of AutoComplete component
    AutoCompleteObj;
    componentDidMount() {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                proxy.AutoCompleteObj.inputElement.focus();
            }
        };
    }
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" ref={(scope) => { this.AutoCompleteObj = scope; }} fields={this.fields} dataSource={this.gameList} placeholder="Find a game"/>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { AutoCompleteComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

export default class App extends React.Component<{}, {}> {
    // defined the array of data
    private gameList: { [key: string]: Object }[] = [
        { Id: 'Game1', Game: 'Badminton' },
        { Id: 'Game2', Game: 'Basketball' },
        { Id: 'Game3', Game: 'Cricket' },
        { Id: 'Game4', Game: 'Football' },
        { Id: 'Game5', Game: 'Golf' },
        { Id: 'Game6', Game: 'Hockey' },
        { Id: 'Game7', Game: 'Rugby' },
        { Id: 'Game8', Game: 'Snooker' }
    ];

    // maps the appropriate column to fields property
    private fields: object = { value: 'Game' };

    // instance of AutoComplete component
    private AutoCompleteObj: AutoCompleteComponent;

    public componentDidMount() {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                (proxy.AutoCompleteObj as any).inputElement.focus();
            }
        };
    }

    public render() {
        return (
            // specifies the tag for render the AutoComplete component
            <AutoCompleteComponent id="atcelement" ref={(scope) => { (this.AutoCompleteObj as AutoCompleteComponent | null) = scope; }} fields={this.fields} dataSource={this.gameList} placeholder="Find a game" />
        );
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

import { AutoCompleteComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
    // defined the array of data
    const gameList = [
        { Id: 'Game1', Game: 'Badminton' },
        { Id: 'Game2', Game: 'Basketball' },
        { Id: 'Game3', Game: 'Cricket' },
        { Id: 'Game4', Game: 'Football' },
        { Id: 'Game5', Game: 'Golf' },
        { Id: 'Game6', Game: 'Hockey' },
        { Id: 'Game7', Game: 'Rugby' },
        { Id: 'Game8', Game: 'Snooker' }
    ];
    // maps the appropriate column to fields property
    const fields = { value: 'Game' };
    // instance of AutoComplete component
    let AutoCompleteObj;
    React.useEffect(() => {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                proxy.AutoCompleteObj.inputElement.focus();
            }
        };
    }, []);
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" ref={(scope) => { AutoCompleteObj = scope; }} fields={fields} dataSource={gameList} placeholder="Find a game"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { AutoCompleteComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

function App() {
    // defined the array of data
    const gameList: { [key: string]: Object }[] = [
        { Id: 'Game1', Game: 'Badminton' },
        { Id: 'Game2', Game: 'Basketball' },
        { Id: 'Game3', Game: 'Cricket' },
        { Id: 'Game4', Game: 'Football' },
        { Id: 'Game5', Game: 'Golf' },
        { Id: 'Game6', Game: 'Hockey' },
        { Id: 'Game7', Game: 'Rugby' },
        { Id: 'Game8', Game: 'Snooker' }
    ];

    // maps the appropriate column to fields property
    const fields: object = { value: 'Game' };

    // instance of AutoComplete component
    let AutoCompleteObj: AutoCompleteComponent;
    React.useEffect(() => {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                (proxy.AutoCompleteObj as any).inputElement.focus();
            }
        };
    }, []);
    return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" ref={(scope) => { (AutoCompleteObj as AutoCompleteComponent | null) = scope; }} fields={fields} dataSource={gameList} placeholder="Find a game" />
    );
}
ReactDOM.render(<App />, document.getElementById('sample'));

Ensuring accessibility

The AutoComplete component’s accessibility levels are ensured through an accessibility-checker and axe-core software tools during automated testing.

The accessibility compliance of the AutoComplete component is shown in the following sample. Open the sample in a new window to evaluate the accessibility of the AutoComplete component with accessibility tools.

See also