Skip to content

Commit

Permalink
feat(a11y): added new prop for a11y module - scrollOnFocus (#7632)
Browse files Browse the repository at this point in the history
* added new prop for a11y module - scrollOnFocus

* added props to handleFocus
  • Loading branch information
SlDo authored Jul 23, 2024
1 parent 1bb2746 commit f4f7da0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/modules/a11y/a11y.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function A11y({ swiper, extendParams, on }) {
itemRoleDescriptionMessage: null,
slideRole: 'group',
id: null,
scrollOnFocus: true
},
});

Expand Down Expand Up @@ -236,7 +237,7 @@ export default function A11y({ swiper, extendParams, on }) {
};

const handleFocus = (e) => {
if (swiper.a11y.clicked) return;
if (swiper.a11y.clicked || !swiper.params.a11y.scrollOnFocus) return;
if (new Date().getTime() - visibilityChangedTimestamp < 100) return;

const slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`);
Expand Down
7 changes: 7 additions & 0 deletions src/types/modules/a11y.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ export interface A11yOptions {
* @default null
*/
id?: string | number | null;

/**
* Enables scrolling to the slide that has been focused
*
* @default true
*/
scrollOnFocus?: boolean;
}

0 comments on commit f4f7da0

Please sign in to comment.