'ENTER': 'toggle',
'SPACE': 'toggle',
'ARROW_DOWN': 'next',
- 'ARROW_UP': 'previous'
+ 'ARROW_UP': 'previous',
+ 'HOME': 'first',
+ 'END': 'last',
});
}
_init() {
this._isInitializing = true;
- this.$element.attr('role', 'tablist');
this.$tabs = this.$element.children('[data-accordion-item]');
- this.$tabs.attr({'role': 'presentation'});
this.$tabs.each(function(idx, el) {
var $el = $(el),
$el.find('a:first').attr({
'aria-controls': id,
- 'role': 'tab',
'id': linkId,
- 'aria-expanded': false,
- 'aria-selected': false
+ 'aria-expanded': false
});
- $content.attr({'role': 'tabpanel', 'aria-labelledby': linkId, 'aria-hidden': true, 'id': id});
+ $content.attr({'role': 'region', 'aria-labelledby': linkId, 'aria-hidden': true, 'id': id});
});
var $initActive = this.$element.find('.is-active').children('[data-tab-content]');
$a.trigger('click.zf.accordion')
}
},
+ first: function() {
+ var $a = _this.$tabs.first().find('.accordion-title').focus();
+ if (!_this.options.multiExpand) {
+ $a.trigger('click.zf.accordion');
+ }
+ },
+ last: function() {
+ var $a = _this.$tabs.last().find('.accordion-title').focus();
+ if (!_this.options.multiExpand) {
+ $a.trigger('click.zf.accordion');
+ }
+ },
handled: function() {
e.preventDefault();
}
$targetItem.addClass('is-active');
$(`#${targetContentId}`).attr({
- 'aria-expanded': true,
- 'aria-selected': true
+ 'aria-expanded': true
});
$target.finish().slideDown(this.options.slideSpeed, () => {
$targetItem.removeClass('is-active');
$(`#${targetContentId}`).attr({
- 'aria-expanded': false,
- 'aria-selected': false
+ 'aria-expanded': false
});
$target.finish().slideUp(this.options.slideSpeed, () => {
updateHistory: false
};
-export { Accordion };
+export { Accordion };
\ No newline at end of file
plugin.$element.should.be.an('object');
plugin.options.should.be.an('object');
});
-
- it('applies role="presentation" to the list item to conform with WAI', function () {
- $html = $(template).appendTo('body');
- plugin = new Foundation.Accordion($html, {allowAllClosed: true});
-
- $html.find('.accordion-item').eq(0).should.have.attr('role', 'presentation');
- });
});
describe('up()', function(done) {
plugin.up($html.find('.accordion-content').eq(0));
$html.find('.accordion-title').eq(0).should.have.attr('aria-expanded', 'false');
- $html.find('.accordion-title').eq(0).should.have.attr('aria-selected', 'false');
});
it('not closes the open container if allowAllClosed is false', function() {
plugin.down($html.find('.accordion-content').eq(1));
$html.find('.accordion-title').eq(1).should.have.attr('aria-expanded', 'true');
- $html.find('.accordion-title').eq(1).should.have.attr('aria-selected', 'true');
});
it('closes open container if multiExpand is false', function(done) {
// Check if focus was moved
$html.find('.accordion-title').eq(1)[0].should.be.equal(document.activeElement);
});
+ it('opens first panel on HOME', function() {
+ $html = $(template).appendTo('body');
+ plugin = new Foundation.Accordion($html, {});
+
+ $html.find('.accordion-title').eq(1).focus()
+ .trigger(window.mockKeyboardEvent('HOME'));
+
+ $html.find('.accordion-content').eq(0).should.be.visible;
+ $html.find('.accordion-content').eq(0).should.have.attr('aria-hidden', 'false');
+ // Check if focus was moved
+ $html.find('.accordion-title').eq(0)[0].should.be.equal(document.activeElement);
+ });
+ it('opens last panel on END', function() {
+ $html = $(template).appendTo('body');
+ plugin = new Foundation.Accordion($html, {});
+
+ $html.find('.accordion-title').eq(1).focus()
+ .trigger(window.mockKeyboardEvent('END'));
+
+ $html.find('.accordion-content').eq(2).should.be.visible;
+ $html.find('.accordion-content').eq(2).should.have.attr('aria-hidden', 'false');
+ // Check if focus was moved
+ $html.find('.accordion-title').eq(2)[0].should.be.equal(document.activeElement);
+ });
it('opens related panel on ENTER', function() {
$html = $(template).appendTo('body');
plugin = new Foundation.Accordion($html, {});