Skip to content

Commit

Permalink
fix(a11y): space should trigger role button
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Feb 23, 2021
1 parent a863b99 commit 3d4039b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/components/a11y/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ const A11y = {
$el.attr('aria-disabled', false);
return $el;
},
onEnterKey(e) {
onEnterOrSpaceKey(e) {
if (e.keyCode !== 13 && e.keyCode !== 32) return;
const swiper = this;
const params = swiper.params.a11y;
if (e.keyCode !== 13) return;
const $targetEl = $(e.target);
if (swiper.navigation && swiper.navigation.$nextEl && $targetEl.is(swiper.navigation.$nextEl)) {
if (!(swiper.isEnd && !swiper.params.loop)) {
Expand Down Expand Up @@ -184,7 +184,7 @@ const A11y = {
swiper.a11y.makeElFocusable($nextEl);
if ($nextEl[0].tagName !== 'BUTTON') {
swiper.a11y.addElRole($nextEl, 'button');
$nextEl.on('keydown', swiper.a11y.onEnterKey);
$nextEl.on('keydown', swiper.a11y.onEnterOrSpaceKey);
}
swiper.a11y.addElLabel($nextEl, params.nextSlideMessage);
swiper.a11y.addElControls($nextEl, wrapperId);
Expand All @@ -193,7 +193,7 @@ const A11y = {
swiper.a11y.makeElFocusable($prevEl);
if ($prevEl[0].tagName !== 'BUTTON') {
swiper.a11y.addElRole($prevEl, 'button');
$prevEl.on('keydown', swiper.a11y.onEnterKey);
$prevEl.on('keydown', swiper.a11y.onEnterOrSpaceKey);
}
swiper.a11y.addElLabel($prevEl, params.prevSlideMessage);
swiper.a11y.addElControls($prevEl, wrapperId);
Expand All @@ -209,7 +209,7 @@ const A11y = {
swiper.pagination.$el.on(
'keydown',
`.${swiper.params.pagination.bulletClass.replace(/ /g, '.')}`,
swiper.a11y.onEnterKey,
swiper.a11y.onEnterOrSpaceKey,
);
}
},
Expand All @@ -227,10 +227,10 @@ const A11y = {
$prevEl = swiper.navigation.$prevEl;
}
if ($nextEl) {
$nextEl.off('keydown', swiper.a11y.onEnterKey);
$nextEl.off('keydown', swiper.a11y.onEnterOrSpaceKey);
}
if ($prevEl) {
$prevEl.off('keydown', swiper.a11y.onEnterKey);
$prevEl.off('keydown', swiper.a11y.onEnterOrSpaceKey);
}

// Pagination
Expand All @@ -243,7 +243,7 @@ const A11y = {
swiper.pagination.$el.off(
'keydown',
`.${swiper.params.pagination.bulletClass.replace(/ /g, '.')}`,
swiper.a11y.onEnterKey,
swiper.a11y.onEnterOrSpaceKey,
);
}
},
Expand Down

0 comments on commit 3d4039b

Please sign in to comment.