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

added new prop for a11y module - scrollOnFocus #7632

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
}