* @private
*/
_init() {
+ // Collect triggers to set ARIA attributes to
+ var id = this.$element[0].id,
+ $triggers = $(`[data-open~="${id}"], [data-close~="${id}"], [data-toggle~="${id}"]`);
+
var input;
// Parse animation classes if they were set
if (this.options.animate) {
this.animationIn = input[0];
this.animationOut = input[1] || null;
+
+ // - aria-expanded: according to the element visibility.
+ $triggers.attr('aria-expanded', !this.$element.is(':hidden'));
}
// Otherwise, parse toggle class
else {
}
// Allow for a . at the beginning of the string
this.className = input[0] === '.' ? input.slice(1) : input;
- }
- // Add ARIA attributes to triggers:
- var id = this.$element[0].id,
- $triggers = $(`[data-open~="${id}"], [data-close~="${id}"], [data-toggle~="${id}"]`);
+ // - aria-expanded: according to the elements class set.
+ $triggers.attr('aria-expanded', this.$element.hasClass(this.className));
+ }
- // - aria-expanded: according to the element visibility.
- $triggers.attr('aria-expanded', !this.$element.is(':hidden'));
// - aria-controls: adding the element id to it if not already in it.
$triggers.each((index, trigger) => {
const $trigger = $(trigger);
$triggers.remove();
});
- it('sets aria-expanded to true if the element is visible', function() {
+ it('sets aria-expanded to false if the element has toggler class and no animate and toggler class not in class set', function() {
$html = $('<div id="toggler" data-toggler="class"></div>').appendTo('body');
var $triggers = appendTriggers();
plugin = new Foundation.Toggler($html, {});
+ $triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-expanded', 'false');
+ $triggers.remove();
+ });
+
+ it('sets aria-expanded to true if the element has toggler class and no animate and toggler class is in class set', function() {
+ $html = $('<div id="toggler" class="class" data-toggler="class"></div>').appendTo('body');
+ var $triggers = appendTriggers();
+ plugin = new Foundation.Toggler($html, {});
+
$triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-expanded', 'true');
$triggers.remove();
});
- it('sets aria-expanded to false if the element is invisible', function() {
+ it('sets aria-expanded to true if the element is visible and animate set', function() {
+ $html = $('<div id="toggler" data-animate="hinge-in-from-top spin-out"></div>').appendTo('body');
+ var $triggers = appendTriggers();
+ plugin = new Foundation.Toggler($html, {});
+
+ $triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-expanded', 'true');
+ $triggers.remove();
+ });
+
+ it('sets aria-expanded to false if the element is invisible and animate set', function() {
var $css = $('<style>#toggler { display: none }</style>').appendTo('body');
- $html = $('<div id="toggler" data-toggler="class"></div>').appendTo('body');
+ $html = $('<div id="toggler" data-animate="hinge-in-from-top spin-out"></div>').appendTo('body');
var $triggers = appendTriggers();
plugin = new Foundation.Toggler($html, {});