Accessibility in EJ2 JavaScript Context menu control
2 May 20235 minutes to read
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. ContextMenu provides built-in compliance with WAI-ARIA
specifications. WAI-ARIA
support is achieved through the attributes like aria-expanded
and aria-haspopup
applied for menu item in ContextMenu. It helps the people with disabilities by providing information about the widget for assistive technology in the screen readers. ContextMenu component contains the menu
role and menuItem
role.
Properties | Functionality |
---|---|
menu | This role will be specified for an item which 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, as well as indicates whether its current state is expanded or collapsed. |
Keyboard interaction
Keyboard shortcuts | Actions |
Esc | Closes the opened ContextMenu. |
Enter | Selects the focused item. |
Up | Navigates up or to the previous menu item. |
Down | Navigates down or to the next menu item. |
Left | Close the current sub menu and navigates to the parent menu. |
Right | Navigates and open the next sub menu. |
ej.base.enableRipple(true);
var menuItems = [
{
text: 'Cut',
iconCss: 'e-db-icons e-cut'
},
{
text: 'Copy',
iconCss: 'e-icons e-copy'
},
{
text: 'Paste',
iconCss: 'e-db-icons e-paste',
items: [
{
text: 'Paste Text',
iconCss: 'e-cm-icons e-pastetext'
},
{
text: 'Paste Special',
iconCss: 'e-cm-icons e-pastespecial'
} ]
}];
var menuOptions = {
items: menuItems,
target: '#target'
};
var menuObj = new ej.navigations.ContextMenu(menuOptions, '#contextmenu');
menuObj.open(40, 20);
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="Essential JS 2">
<meta name="author" content="Syncfusion">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-lists/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-navigations/styles/material.css" rel="stylesheet">
<!--style reference from app-->
<link href="styles.css" rel="stylesheet">
<!--system js reference and configuration-->
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<!--element which is going to render-->
<div id="target">Right click / Touch hold to open the ContextMenu</div>
<ul id="contextmenu"></ul>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>