I've created an overlay that loads content dynamically after it opens, but am having issues with VoiceOver in Safari when trying to add ARIA attributes.
After only adding role='dialog'
to the overlay container, it is announced as a dialog, but reads the text contents first ("close loading... dialog close button").
When adding a label to the dialog with either aria-label
and aria-labelledby
the real problem occurs. The overlay is announced nicely ("Overlay dialog close button"), but then the rest of the dialog's contents are inaccessible after being loaded, and it just appears that the close button is the last (and only) item available.
HTML:
<div id="page">
<a id="opendialog" href="#" role="button">Open</a>
</div>
JavaScript:
jQuery(function ($) {
$('#opendialog').click(function (event) {
event.preventDefault();
// Attach the dialog container to the page with a loading placeholder.
$dialog = $('<div id="dialog" role="dialog" aria-labelledby="dialog-label">' +
'<span id="dialog-label">Overlay</span>' +
'<a href="#" class="close" role="button">close</a>' +
'<div class="content"><span class="loading">Loading...</span></div>' +
'</div>')
.insertAfter('#page');
$dialog.find('.close').focus();
// Hide the other page contents to trap the user in the dialog.
$('#page').hide();
$dialog.find('.close').click(function (event) {
event.preventDefault();
$dialog.remove();
$('#page').show();
$('#opendialog').focus();
});
// Simulate an asynchronous request for the dialog contents.
setTimeout(function () {
$dialog.find('.content .loading')
.replaceWith('<div>Dialog Content</div>');
}, 250);
});
});
http://codepen.io/gapple/pen/FGhzl
Chrome also seems to have some weird issues with the codepen when in an iframe, but loading the iframe url directly seems to work correctly.