Search results

Accessibility in React Menu component

ARIA attributes

The web accessibility makes web content and web applications more accessible for people with disabilities. It especially helps in dynamic content change and development of advanced user interface controls with AJAX, HTML, JavaScript, and related technologies. The menu provides a built-in compliance with WAI-ARIA specifications. The WAI-ARIA support is achieved using the attributes such as aria-orientation, aria-label, aria-expanded, aria-disabled, and aria-haspopup applied for menu item in menu. It helps the people with disabilities by providing information about the widget for assistive technology in the screen readers. The menu component contains the menubar, menu, and menuItem roles.

Properties Functionality
menubar This role will be specified for root menu.
menu This role will be specified for an item that have sub menu.
menuitem This role will be specified for an item that do not have sub menus.
aria-haspopup Indicates the availability and type of interactive popup element.
aria-expanded Indicates whether the subtree can be expanded or collapsed, and indicates whether its current state can be expanded or collapsed.
aria-orientation Indicates whether the orientation is horizontal or vertical. The default orientation is horizontal.
aria-label Indicates the menu item text.
aria-disabled Indicates the state of menu item whether it is disabled.

User interaction with keyboard

Keyboard shortcuts Actions
Esc Closes the sub menu that contains focus and returns focus to the parent element.
Enter Opens the sub menu if focused menu item has sub menu, and places focus on its first item or activates the item and closes the sub menu.
Up Navigates up or to the previous menu item.
Down Navigates down or to the next menu item.
Left Closes the current sub menu and navigates to the parent menu.
Right Navigates and open the next sub menu.
Home Focuses the first item.
End Focuses the last item.
Source
Preview
index.tsx
index.html
index.jsx
import { enableRipple } from '@syncfusion/ej2-base';
import { MenuComponent, MenuItemModel } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDom from 'react-dom';

enableRipple(true);

class App extends React.Component<{}, {}> {
    // Menu items definition
    public menuItems: MenuItemModel[] = [
        {
            items: [
                {
                    items: [
                        {
                            items: [
                                { text: 'Trimmers' },
                                { text:  'Shavers' }
                            ],
                            text: 'Personal Care'
                        },
                        {
                            items: [
                                { text: 'Shirts' },
                                { text: 'Jackets' },
                                { text: 'Track Suits' }
                            ],
                            text: 'Clothing'
                        },
                        { text: 'Footwear' }
                    ],
                    text: 'Men Fashion'
                },
                {
                    items: [
                        {
                            items: [
                                { text: 'Kurtas' },
                                { text: 'Salwars' },
                                { text: 'Sarees' }
                            ],
                            text: 'Clothing'
                        },
                        {
                            items: [
                                { text: 'Nosepins' },
                                { text:  'Anklets' }
                            ],
                            text: 'Jewellery'
                        }
                    ],
                    text: 'Women Fashion'
                }
            ],
            text: 'Fashion'
        },
        {
            items: [
                {
                    items: [
                        { text: 'Fully Automatic' },
                        { text: 'Semi Automatic' }
                    ],
                    text: 'Washing Machine'
                },
                {
                    items: [
                        { text: 'Inverter ACs' },
                        { text: 'Split ACs' }
                    ],
                    text: 'Air Conditioners'
                }
            ],
            text: 'Home & Living'
        },
        { text: 'Sports' },
        { text: 'Gaming' }
    ];
    public render() {
        return (
            <MenuComponent items={this.menuItems}/>
        );
    }
}

ReactDom.render(<App />,document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React ContextMenu</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>

</html>
import { enableRipple } from '@syncfusion/ej2-base';
import { MenuComponent } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
class App extends React.Component {
    constructor() {
        super(...arguments);
        // Menu items definition
        this.menuItems = [
            {
                items: [
                    {
                        items: [
                            {
                                items: [
                                    { text: 'Trimmers' },
                                    { text: 'Shavers' }
                                ],
                                text: 'Personal Care'
                            },
                            {
                                items: [
                                    { text: 'Shirts' },
                                    { text: 'Jackets' },
                                    { text: 'Track Suits' }
                                ],
                                text: 'Clothing'
                            },
                            { text: 'Footwear' }
                        ],
                        text: 'Men Fashion'
                    },
                    {
                        items: [
                            {
                                items: [
                                    { text: 'Kurtas' },
                                    { text: 'Salwars' },
                                    { text: 'Sarees' }
                                ],
                                text: 'Clothing'
                            },
                            {
                                items: [
                                    { text: 'Nosepins' },
                                    { text: 'Anklets' }
                                ],
                                text: 'Jewellery'
                            }
                        ],
                        text: 'Women Fashion'
                    }
                ],
                text: 'Fashion'
            },
            {
                items: [
                    {
                        items: [
                            { text: 'Fully Automatic' },
                            { text: 'Semi Automatic' }
                        ],
                        text: 'Washing Machine'
                    },
                    {
                        items: [
                            { text: 'Inverter ACs' },
                            { text: 'Split ACs' }
                        ],
                        text: 'Air Conditioners'
                    }
                ],
                text: 'Home & Living'
            },
            { text: 'Sports' },
            { text: 'Gaming' }
        ];
    }
    render() {
        return (<MenuComponent items={this.menuItems}/>);
    }
}
ReactDom.render(<App />, document.getElementById('element'));