Skip to content
Snippets Groups Projects
Commit 98cddda4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2472177 by Dom., nod_, drubb, mgifford: Collapsible fieldset have...

Issue #2472177 by Dom., nod_, drubb, mgifford: Collapsible fieldset have duplicated and wrong aria-expanded
parent 7b948696
No related branches found
No related tags found
No related merge requests found
......@@ -124,6 +124,7 @@ drupal.batch:
drupal.collapse:
version: VERSION
js:
misc/details-aria.js: {}
misc/collapse.js: {}
dependencies:
- core/jquery
......
......@@ -225,7 +225,7 @@ function template_preprocess_details(&$variables) {
if (!empty($element['#attributes']['id'])) {
$variables['summary_attributes']['aria-controls'] = $element['#attributes']['id'];
}
$variables['summary_attributes']['aria-expanded'] = !empty($element['#attributes']['open']);
$variables['summary_attributes']['aria-expanded'] = !empty($element['#attributes']['open']) ? 'true' : 'false';
$variables['summary_attributes']['aria-pressed'] = $variables['summary_attributes']['aria-expanded'];
}
$variables['title'] = (!empty($element['#title'])) ? $element['#title'] : '';
......
......@@ -91,7 +91,11 @@
else {
$summaryPrefix.html(Drupal.t('Hide'));
}
this.$node.attr('open', !isOpen);
// Delay setting the attribute to emulate chrome behavior and make
// details-aria.js work as expected with this polyfill.
setTimeout(function () {
this.$node.attr('open', !isOpen);
}.bind(this), 0);
}
});
......
/**
* @file
* Add aria attribute handling for details and summary elements.
*/
(function ($, Drupal) {
"use strict";
Drupal.behaviors.detailsAria = {
attach: function () {
$('body').once('detailsAria').on('click.detailsAria', 'summary', function (event) {
var $summary = $(event.currentTarget);
var open = $(event.currentTarget.parentNode).attr('open') === 'open' ? 'false' : 'true';
$summary.attr({
'aria-expanded': open,
'aria-pressed': open
});
});
}
};
})(jQuery, Drupal);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment