Security update for Core, with self-updated composer
[yaffs-website] / web / core / misc / details-aria.es6.js
diff --git a/web/core/misc/details-aria.es6.js b/web/core/misc/details-aria.es6.js
new file mode 100644 (file)
index 0000000..bf92846
--- /dev/null
@@ -0,0 +1,25 @@
+/**
+ * @file
+ * Add aria attribute handling for details and summary elements.
+ */
+
+(function ($, Drupal) {
+  /**
+   * Handles `aria-expanded` and `aria-pressed` attributes on details elements.
+   *
+   * @type {Drupal~behavior}
+   */
+  Drupal.behaviors.detailsAria = {
+    attach() {
+      $('body').once('detailsAria').on('click.detailsAria', 'summary', (event) => {
+        const $summary = $(event.currentTarget);
+        const open = $(event.currentTarget.parentNode).attr('open') === 'open' ? 'false' : 'true';
+
+        $summary.attr({
+          'aria-expanded': open,
+          'aria-pressed': open,
+        });
+      });
+    },
+  };
+}(jQuery, Drupal));