Search results

Accessibility in JavaScript (ES5) Dialog control

The Dialog characterized with complete ARIA Accessibility support which helps to accessible by on-screen readers and other assistive technology devices. This component designed with the reference of the guidelines document given in WAI ARAI Accessibility Practices.

The Dialog component uses the Dialog role and following ARIA properties to its element based on its state.

Property Functionalities
aria-describedby It indicates the Dialog content description is notified to the user through assistive technologies.
aria-labelledby The Dialog title is notified to the user through assistive technologies.
aria-modal For modal dialog it’s value is true and non-modal dialog its value is false
aria-grabbed Enable the draggable Dialog and starts dragging it is value is true and stopping the drag its value is false

Keyboard interaction

Keyboard interaction of Dialog component has designed based on WAI-ARIA Practices described for Dialog. User can use the following shortcut keys to interact with the Dialog.

Keyboard shortcuts Actions
Esc Closes the Dialog. This functionality can be controlled by using `closeOnEscape`
Enter When the Dialog button or any input (except text area) is in focus state, when pressing the Enter key, the click event associated with the primary button or button will trigger. Enter key is not working when the Dialog content contains any text area with initial focus
Ctrl + Enter When the Dialog content contains text area and it is in focus state, and press the Ctrl + Enter key to call the click event function associated with primary button
Tab Focus will be changed within the Dialog elements
Shift + Tab The Focus will be changed previous focusable element within the Dialog elements. When focusing a first focusable element in the Dialog, then press the shift + tab key, it will change the focus to last focusable element
Source
Preview
index.js
index.html
styles.css
ej.base.enableRipple(true);

// Initialize Dialog component
var dialog = new ej.popups.Dialog({
    // Enables the header
    header: 'Feedback',
    // Dialog content
    content: document.getElementById("dlgContent"),
    // Enables the close icon in header
    showCloseIcon: true,
    // Enables the footer buttons
    buttons: [{
            // Accessing button component properties by buttonModel property
            buttonModel: {
                //Enables the primary button
                isPrimary: true,
                content: 'Submit'
            },
            // Click the footer buttons to hide the Dialog
            click: function () {
                this.hide();
            }
        }],
    // The Dialog shows within the target element
    target: document.getElementById("container"),
    // Dialog width
    width: '400px',
    // Dialog height
    height: '330px',
    beforeOpen: onBeforeopen
});
// Render initialized Dialog
dialog.appendTo('#dialog');

// Sample level code to handle the button click action
document.getElementById('targetButton').onclick = function () {
    // Call the show method to open the Dialog
    dialog.show();
};

function onBeforeopen() {
    document.getElementById('dlgContent').style.visibility = 'visible';
}
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Dialog</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="TypeScript UI Components">
    <meta name="author" content="Syncfusion">
    <link href="styles.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <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-inputs/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <button class="e-control e-btn" id="targetButton" role="button" e-ripple="true" style="position: absolute;">Open Dialog</button>
        <div id="dialog"></div>
        <form id="dlgContent" style="visibility: hidden">
           <div class="form-group"><label for="email">Email:</label>
             <input type="email" class="form-control" id="email">
           </div>
            <div class="form-group">
                <label for="comment">Comments:</label>
                <textarea style="resize: none;" class="form-control" rows="4" id="comment"></textarea>
            </div>
        </form>
    </div>

<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>
html,
body,    
#container {
    height: 100%;
    overflow: hidden;
    width: 100%;
}

#loader {
    color: #008cff;
    height: 40px;
    left: 45%;
    position: absolute;
    top: 45%;  
    width: 30%;
}

See Also