details-aria.es6.js 659 B

12345678910111213141516171819202122232425
  1. /**
  2. * @file
  3. * Add aria attribute handling for details and summary elements.
  4. */
  5. (function ($, Drupal) {
  6. /**
  7. * Handles `aria-expanded` and `aria-pressed` attributes on details elements.
  8. *
  9. * @type {Drupal~behavior}
  10. */
  11. Drupal.behaviors.detailsAria = {
  12. attach() {
  13. $('body').once('detailsAria').on('click.detailsAria', 'summary', (event) => {
  14. const $summary = $(event.currentTarget);
  15. const open = $(event.currentTarget.parentNode).attr('open') === 'open' ? 'false' : 'true';
  16. $summary.attr({
  17. 'aria-expanded': open,
  18. 'aria-pressed': open,
  19. });
  20. });
  21. },
  22. };
  23. }(jQuery, Drupal));