Accessibility in React Combo box component

26 Jan 202418 minutes to read

The ComboBox 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 ComboBox 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 ComboBox component is outlined below.

Accessibility Criteria Compatibility
WCAG 2.2 Support Yes
Section 508 Support Yes
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 ComboBox component followed the WAI-ARIA patterns to meet the accessibility. The following ARIA attributes are used in the ComboBox component:

Properties Functionalities
aria-haspopup Indicates whether the ComboBox input element has a popup list or not.
aria-expanded Indicates whether the popup list has expanded or not.
aria-selected Indicates the selected option.
aria-readonly Indicates the readonly state of the ComboBox element.
aria-disabled Indicates whether the ComboBox 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 popup 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 ComboBox without interruptions.

Keyboard shortcuts Actions
Arrow Down Selects the first item in the ComboBox when no item selected. Otherwise, selects the item next to the currently selected item.
Arrow Up 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 the previous page and selects the first item when popup list opens.
Enter Selects the focused item and popup list closes when it is in open state.
Tab Focuses on the next TabIndex element on the page when the popup is closed. Otherwise, closes the popup list and remains the focus of the component.
Shift + tab Focuses on the previous TabIndex element on the page when the popup is closed. Otherwise, closes the popup list and remains the focus of the component.
Alt + Down Open the popup list
Alt + Up Close the popup list
Esc(Escape) Closes the popup list when it is in an open state and the currently selected item remains the same.
Home Cursor moves to before of first character in input
End Cursor moves to next of last character in input

In the below sample, alt+t keys are used to focus the ComboBox component.

[Class-component]

import { ComboBoxComponent } 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: 'Game2', Game: 'Badminton' },
        { Id: 'Game3', Game: 'Basketball' },
        { Id: 'Game4', Game: 'Cricket' },
        { Id: 'Game5', Game: 'Football' },
        { Id: 'Game6', Game: 'Golf' },
        { Id: 'Game7', Game: 'Hockey' },
        { Id: 'Game8', Game: 'Rugby' },
        { Id: 'Game9', Game: 'Snooker' },
        { Id: 'Game10', Game: 'Tennis' },
    ];
    // maps the appropriate column to fields property
    fields = { text: 'Game', value: 'Id' };
    // instance of ComboBox component
    comboBoxObj;
    componentDidMount() {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                proxy.comboBoxObj.inputElement.focus();
            }
        };
    }
    render() {
        return (
        // specifies the tag for render the ComboBox component
        <ComboBoxComponent id="comboelement" ref={(scope) => { this.comboBoxObj = scope; }} popupHeight='200px' fields={this.fields} dataSource={this.gameList} placeholder="Select a game"/>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { ComboBoxComponent } 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: 'Game2', Game: 'Badminton' },
        { Id: 'Game3', Game: 'Basketball' },
        { Id: 'Game4', Game: 'Cricket' },
        { Id: 'Game5', Game: 'Football' },
        { Id: 'Game6', Game: 'Golf' },
        { Id: 'Game7', Game: 'Hockey' },
        { Id: 'Game8', Game: 'Rugby' },
        { Id: 'Game9', Game: 'Snooker' },
        { Id: 'Game10', Game: 'Tennis' },
    ];

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

    // instance of ComboBox component
    private comboBoxObj: ComboBoxComponent;

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

    public render() {
        return (
            // specifies the tag for render the ComboBox component
            <ComboBoxComponent id="comboelement" ref={(scope) => { (this.comboBoxObj as ComboBoxComponent | null) = scope; }} popupHeight='200px' fields={this.fields} dataSource={this.gameList} placeholder="Select a game" />
        );
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

import { ComboBoxComponent } 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: 'Game2', Game: 'Badminton' },
        { Id: 'Game3', Game: 'Basketball' },
        { Id: 'Game4', Game: 'Cricket' },
        { Id: 'Game5', Game: 'Football' },
        { Id: 'Game6', Game: 'Golf' },
        { Id: 'Game7', Game: 'Hockey' },
        { Id: 'Game8', Game: 'Rugby' },
        { Id: 'Game9', Game: 'Snooker' },
        { Id: 'Game10', Game: 'Tennis' },
    ];
    // maps the appropriate column to fields property
    const fields = { text: 'Game', value: 'Id' };
    // instance of ComboBox component
    let comboBoxObj;
    React.useEffect(() => {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                proxy.comboBoxObj.inputElement.focus();
            }
        };
    }, []);
    return (
    // specifies the tag for render the ComboBox component
    <ComboBoxComponent id="comboelement" ref={(scope) => { comboBoxObj = scope; }} popupHeight='200px' fields={fields} dataSource={gameList} placeholder="Select a game"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { ComboBoxComponent } 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: 'Game2', Game: 'Badminton' },
        { Id: 'Game3', Game: 'Basketball' },
        { Id: 'Game4', Game: 'Cricket' },
        { Id: 'Game5', Game: 'Football' },
        { Id: 'Game6', Game: 'Golf' },
        { Id: 'Game7', Game: 'Hockey' },
        { Id: 'Game8', Game: 'Rugby' },
        { Id: 'Game9', Game: 'Snooker' },
        { Id: 'Game10', Game: 'Tennis' },
    ];

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

    // instance of ComboBox component
    let comboBoxObj: ComboBoxComponent;
    React.useEffect(() => {
        const proxy = this;
        document.onkeyup = (e) => {
            if (e.altKey && e.keyCode === 84 /* t */) {
                // press alt+t to focus the control.
                (proxy.comboBoxObj as any).inputElement.focus();
            }
        };
}, []);

    return (
    // specifies the tag for render the ComboBox component
        <ComboBoxComponent id="comboelement" ref={(scope) => { (comboBoxObj as ComboBoxComponent | null) = scope; }} popupHeight='200px' fields={fields} dataSource={gameList} placeholder="Select a game" />
    );
}
ReactDOM.render(<App />, document.getElementById('sample'));

Ensuring accessibility

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

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

See also