sebnitu / vrembem

A CSS component library based on the BEM methodology.

Home Page:https://vrembem.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add more accessibility attributes to JS component implementations

sebnitu opened this issue · comments

Problem

There are some accessibility improvements that can be made to the markup of JavaScript components such as modals and draw modal states by adding various aria and role attributes. Here are a few that should be looked into to see if it makes sense to add:

  • role="dialog" - Add to dialog, modal dialog and drawer dialog elements
  • aria-modal="true" - Add to modal and drawer modal dialog elements

The main question is: should these attributes be added via the JS implementation, or be left to the developer to add manually to their markup. In the case of modal drawers where the state of the drawer switches between modal and inline, it may make more sense to handle these states via the JS.

Example implementation:

// Get the dialog element
const dialog = el.querySelector(`[data-${this.settings.dataDialog}]`);
if (dialog) {
  // Set role to dialog
  dialog.setAttribute('role', 'dialog');

  // Set aria-modal attribute to true
  dialog.setAttribute('aria-modal', 'true');
}

Resources

Fixed in #866