Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessible slick as tablist widget #2119

Merged
merged 28 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6dfe2ef
Remove attributes not needed from default prev/next arrow button markup
cielt Jan 27, 2016
c780461
Remove attributes not needed from slick dot button markup
cielt Jan 27, 2016
0c5e8cf
edit / add key a11y attributes of slick slides
cielt Jan 28, 2016
f7904db
edit a11y attributes of slick dots, treating the carousel as an imple…
cielt Jan 28, 2016
a9c9b35
Merge remote-tracking branch 'upstream/master'
cielt Jan 29, 2016
787dc65
update attributes of slick dots button elements in the context of acc…
cielt Jan 29, 2016
0b98418
introduce aria-selected; update a11y attributes of current slide cont…
cielt Jan 29, 2016
1ebc88f
merging
cielt Jan 29, 2016
1da9503
Merge remote-tracking branch 'upstream/master'
cielt Feb 3, 2016
7cfffd0
Merge remote-tracking branch 'upstream/master'
cielt Feb 10, 2016
645c6a3
adjust slick slide & slick dot aria attribute indices
cielt Feb 10, 2016
8dff2aa
correct slick dots total for aria-label text to nearest containing wh…
cielt Feb 11, 2016
3b4fb45
where a11y true, on slide change set focus to current slide
cielt Feb 11, 2016
0f11b97
add arrow key handler to slick dots where a11y true
cielt Feb 11, 2016
3e11f5b
sync with upstream
cielt Feb 25, 2016
411f5ef
Merge remote-tracking branch 'upstream/master'
cielt Mar 15, 2016
65b2b61
Merge remote-tracking branch 'upstream/master'
cielt Apr 16, 2016
0f521c7
Merge remote-tracking branch 'upstream/master'
cielt May 23, 2016
454010e
edit postSlide behavior such that, instead of setting focus to curren…
cielt Jun 15, 2016
f40ed03
make proper jQuery object before chaining
cielt Jun 27, 2016
98631b2
sync forked branch with upstream/master
cielt Jun 16, 2017
0d7ab43
update accessible slick behavior
cielt Jun 19, 2017
6cab829
Merge remote-tracking branch 'upstream/master'
cielt Jul 7, 2017
c74e4f3
after slide change in accessible slick, set focus to current slide [r…
cielt Jul 7, 2017
66fca9c
set up slides with role=tabpanel, etc. only if slick instance has dot…
cielt Jul 7, 2017
a4ee0bf
allow slick instance to be focussed if .slick-arrow buttons receive f…
cielt Jul 8, 2017
8e490aa
enable arrow key controls while prev/next buttons have focus
cielt Jul 8, 2017
ada9367
update option description in README
cielt Jul 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Example:

Option | Type | Default | Description
------ | ---- | ------- | -----------
accessibility | boolean | true | Enables tabbing and arrow key navigation
accessibility | boolean | true | Enables tabbing and arrow key navigation. Unless `autoplay: true`, sets browser focus to current slide (or first of current slide set, if multiple `slidesToShow`) after slide change.
adaptiveHeight | boolean | false | Adapts slider height to the current slide
autoplay | boolean | false | Enables auto play of slides
autoplaySpeed | int | 3000 | Auto play change interval
Expand Down
80 changes: 69 additions & 11 deletions slick/slick.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,21 @@
.off('mouseenter.slick', $.proxy(_.interrupt, _, true))
.off('mouseleave.slick', $.proxy(_.interrupt, _, false));

if (_.options.accessibility === true) {
_.$dots.off('keydown.slick', _.keyHandler);
}
}

_.$slider.off('focus.slick blur.slick');

if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
_.$prevArrow && _.$prevArrow.off('click.slick', _.changeSlide);
_.$nextArrow && _.$nextArrow.off('click.slick', _.changeSlide);

if (_.options.accessibility === true) {
_.$prevArrow.off('keydown.slick', _.keyHandler);
_.$nextArrow.off('keydown.slick', _.keyHandler);
}
}

_.$list.off('touchstart.slick mousedown.slick', _.swipeHandler);
Expand Down Expand Up @@ -1007,8 +1015,7 @@

_.$slider
.off('focus.slick blur.slick')
.on('focus.slick blur.slick',
'*:not(.slick-arrow)', function(event) {
.on('focus.slick blur.slick', '*', function(event) {

event.stopImmediatePropagation();
var $sf = $(this);
Expand Down Expand Up @@ -1280,25 +1287,62 @@
};

Slick.prototype.initADA = function() {
var _ = this;
var _ = this,
numDotGroups = Math.ceil(_.slideCount / _.options.slidesToShow),
tabControlIndexes = _.getNavigableIndexes().filter(function(val) {
return (val >= 0) && (val < _.slideCount);
});

_.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({
'aria-hidden': 'true',
'tabindex': '-1'
}).find('a, input, button, select').attr({
'tabindex': '-1'
});

_.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) {
$(this).attr('role', 'option');
});

if (_.$dots !== null) {
_.$dots.find('li').each(function(i) {
$(this).find('button').attr({
'id': 'slick-slide' + _.instanceUid + i + ''
});
_.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) {
var slideControlIndex = tabControlIndexes.indexOf(i);

$(this).attr({
'role': 'tabpanel',
'id': 'slick-slide' + _.instanceUid + i,
'tabindex': -1
});

if (slideControlIndex !== -1) {
$(this).attr({
'aria-describedby': 'slick-slide-control' + _.instanceUid + slideControlIndex
});
}
});

_.$dots.attr('role', 'tablist').find('li').each(function(i) {
var mappedSlideIndex = tabControlIndexes[i];

$(this).attr({
'role': 'presentation'
});

$(this).find('button').first().attr({
'role': 'tab',
'id': 'slick-slide-control' + _.instanceUid + i,
'aria-controls': 'slick-slide' + _.instanceUid + mappedSlideIndex,
'aria-label': (i + 1) + ' of ' + numDotGroups,
'aria-selected': null,
'tabindex': '-1'
});

}).eq(_.currentSlide).find('button').attr({
'aria-selected': 'true',
'tabindex': '0'
}).end();
}

for (var i=_.currentSlide, max=i+_.options.slidesToShow; i < max; i++) {
_.$slides.eq(i).attr('tabindex', 0);
}

_.activateADA();

};
Expand All @@ -1318,6 +1362,11 @@
.on('click.slick', {
message: 'next'
}, _.changeSlide);

if (_.options.accessibility === true) {
_.$prevArrow.on('keydown.slick', _.keyHandler);
_.$nextArrow.on('keydown.slick', _.keyHandler);
}
}

};
Expand All @@ -1330,6 +1379,10 @@
$('li', _.$dots).on('click.slick', {
message: 'index'
}, _.changeSlide);

if (_.options.accessibility === true) {
_.$dots.on('keydown.slick', _.keyHandler);
}
}

if ( _.options.dots === true && _.options.pauseOnDotsHover === true ) {
Expand Down Expand Up @@ -1633,6 +1686,11 @@

if (_.options.accessibility === true) {
_.initADA();
// for non-autoplay: once active slide (group) has updated, set focus on first newly showing slide
if (!_.options.autoplay) {
var $currentSlide = $(_.$slides.get(_.currentSlide));
$currentSlide.attr('tabindex', 0).focus();
}
}

}
Expand Down