Skip to content

Commit

Permalink
fix(a11y): don't handle focus on pointer events
Browse files Browse the repository at this point in the history
fixes #5962
fixes #5814
fixes #5524
fixes #5490
fixes #5437
  • Loading branch information
nolimits4web committed Sep 14, 2022
1 parent 0e8a8b8 commit b251601
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/modules/a11y/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default function A11y({ swiper, extendParams, on }) {
},
});

swiper.a11y = {
clicked: false,
};

let liveRegion = null;

function notify(message) {
Expand Down Expand Up @@ -161,8 +165,15 @@ export default function A11y({ swiper, extendParams, on }) {
addElLabel($el, message);
addElControls($el, wrapperId);
};
const handlePointerDown = () => {
swiper.a11y.clicked = true;
};
const handlePointerUp = () => {
swiper.a11y.clicked = false;
};

const handleFocus = (e) => {
if (swiper.a11y.clicked) return;
const slideEl = e.target.closest(`.${swiper.params.slideClass}`);
if (!slideEl || !swiper.slides.includes(slideEl)) return;
const isActive = swiper.slides.indexOf(slideEl) === swiper.activeIndex;
Expand Down Expand Up @@ -258,6 +269,8 @@ export default function A11y({ swiper, extendParams, on }) {

// Tab focus
swiper.$el.on('focus', handleFocus, true);
swiper.$el.on('pointerdown', handlePointerDown, true);
swiper.$el.on('pointerup', handlePointerUp, true);
};
function destroy() {
if (liveRegion && liveRegion.length > 0) liveRegion.remove();
Expand Down Expand Up @@ -288,6 +301,8 @@ export default function A11y({ swiper, extendParams, on }) {

// Tab focus
swiper.$el.off('focus', handleFocus, true);
swiper.$el.off('pointerdown', handlePointerDown, true);
swiper.$el.off('pointerup', handlePointerUp, true);
}

on('beforeInit', () => {
Expand Down

0 comments on commit b251601

Please sign in to comment.