diff --git a/core/misc/collapse.js b/core/misc/collapse.js index 767325e..49dee6f 100644 --- a/core/misc/collapse.js +++ b/core/misc/collapse.js @@ -140,6 +140,34 @@ } }; + /** + * Reveal all children of a grouping element when a child gets the focus. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches behavior for the details element. + */ + Drupal.behaviors.revealChildrenOfGroupedElements = { + attach: function (context) { + $(context).once('revealChildrenOfGroupedElements').on('click', 'a[href^="#"]', function(event) { + var $item = $(event.target.hash); + if ($item.length) { + + // Keep aria attributes in sync as per detailsAria behavior. + $item.parents('details').attr('open', true).find('> summary').attr({ + 'aria-expanded': true, + 'aria-pressed': true + }); + + $item.parents('.vertical-tabs__pane').each(function(index, pane) { + $(pane).data('verticalTab').focus(); + }); + } + }); + } + }; + // Expose constructor in the public space. Drupal.CollapsibleDetails = CollapsibleDetails;