-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keyboard use for component #168
Comments
Agreed. Tingle misses some Accessibility enhancements. For example, dialogs/modals/alert pop-ups should trap focus so users can close the modal without having to tab through all the links on the page that opened the modal. Reading material: https://www.w3.org/WAI/ARIA/apg/patterns/ |
I ended up doing a modified version, which adds role and aria-modal to alert screen readers that this is a modal dialog, and traps focus. This isn't perfect, but gets it closer to WCAG standards. See "//college of education updates" in the gist below. https://gist.github.com/bryanjonker-illinois/a25cdd42f3f44b07d20f041d58892b76 |
@bryanjonker-illinois solution was great - I think it should be merged. In the meantime you can also add it to a normal tingle via the onOpen. function trapInput(modal) {
var modal = document.getElementsByClassName('tingle-modal')[0];
if (modal.lastElementChild.querySelectorAll('button, [href], input, [tabindex="0"], [tabindex="-1"]').length > 0) {
modal.lastElementChild.querySelectorAll('button, [href], input, [tabindex="0"], [tabindex="-1"]')[0].focus();
var lastItem = modal.lastElementChild.querySelectorAll('button, [href], input, [tabindex="0"], [tabindex="-1"]')[modal.lastElementChild.querySelectorAll('button, [href], input, [tabindex="0"], [tabindex="-1"]').length - 1];
lastItem.addEventListener('keydown', function (e) {
if (e.code == "Tab" && !e.shiftKey) {
document.querySelector('.tingle-modal__close').focus();
event.preventDefault();
return false;
}
})
}
} onOpen: function () {
// Sorry for the jQuery below, you could just use setAttribute of course.
$('.tingle-modal-box').attr('role', 'dialog');
$('.tingle-modal-box').attr('aria-modal', true);
trapInput();
}, |
Great component!
However, I am concerned about keyboard accessibility. If someone is restricted to keyboard use only (including screen readers), they cannot interact with the buttons on the screen, and they can fire buttons outside of the dialog box by accident.
See https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal for how the interactions should work.
I ended up tweaking a local copy to meet these guidelines -- let me know if you want to incorporate these changes or handle it yourself. Thanks.
The text was updated successfully, but these errors were encountered: