Skip to content
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

Open
bryanjonker-illinois opened this issue Aug 21, 2021 · 3 comments
Open

Keyboard use for component #168

bryanjonker-illinois opened this issue Aug 21, 2021 · 3 comments

Comments

@bryanjonker-illinois
Copy link

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.

@xaddict
Copy link

xaddict commented Aug 12, 2022

@bryanjonker-illinois
Copy link
Author

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

@MaxwellKeeble
Copy link

@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();
          },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants