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 option to allow next nav element at the end of slides, which returns back to the first slide #5270

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion playground/react/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const App = () => {
slidesPerView={3}
spaceBetween={50}
navigation
loop
allowNextElementAtTheEnd
scrollbar={{ draggable: true }}
pagination={{ clickable: true }}
>
Expand Down
1 change: 1 addition & 0 deletions src/angular/src/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class SwiperComponent implements OnInit {
@Input() longSwipesMs: SwiperOptions['longSwipesMs'];
@Input() followFinger: SwiperOptions['followFinger'];
@Input() allowTouchMove: SwiperOptions['allowTouchMove'];
@Input() allowNextElementAtTheEnd: SwiperOptions['allowNextElementAtTheEnd'];
@Input() threshold: SwiperOptions['threshold'];
@Input() touchMoveStopPropagation: SwiperOptions['touchMoveStopPropagation'];
@Input() touchStartPreventDefault: SwiperOptions['touchStartPreventDefault'];
Expand Down
1 change: 1 addition & 0 deletions src/angular/src/utils/params-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const paramsList = [
'longSwipesMs',
'_followFinger',
'allowTouchMove',
'allowNextElementAtTheEnd',
'_threshold',
'touchMoveStopPropagation',
'touchStartPreventDefault',
Expand Down
2 changes: 2 additions & 0 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class Swiper {
// Touches
allowTouchMove: swiper.params.allowTouchMove,

allowNextElementAtTheEnd: swiper.params.allowNextElementAtTheEnd,

touches: {
startX: 0,
startY: 0,
Expand Down
1 change: 1 addition & 0 deletions src/core/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default {
longSwipesMs: 300,
followFinger: true,
allowTouchMove: true,
allowNextElementAtTheEnd: false,
threshold: 0,
touchMoveStopPropagation: false,
touchStartPreventDefault: true,
Expand Down
10 changes: 7 additions & 3 deletions src/modules/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function Navigation({ swiper, extendParams, on, emit }) {
const { $nextEl, $prevEl } = swiper.navigation;

toggleEl($prevEl, swiper.isBeginning);
toggleEl($nextEl, swiper.isEnd);
toggleEl($nextEl, swiper.isEnd && !swiper.allowNextElementAtTheEnd);
}
function onPrevClick(e) {
e.preventDefault();
Expand All @@ -62,8 +62,12 @@ export default function Navigation({ swiper, extendParams, on, emit }) {
}
function onNextClick(e) {
e.preventDefault();
if (swiper.isEnd && !swiper.params.loop) return;
swiper.slideNext();
if (swiper.isEnd && !swiper.params.loop && !swiper.allowNextElementAtTheEnd) return;
if (swiper.isEnd && swiper.allowNextElementAtTheEnd) {
swiper.slideTo(0);
} else {
swiper.slideNext();
}
}
function init() {
const params = swiper.params.navigation;
Expand Down
1 change: 1 addition & 0 deletions src/react/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const paramsList = [
'longSwipesMs',
'_followFinger',
'allowTouchMove',
'allowNextElementAtTheEnd',
'_threshold',
'touchMoveStopPropagation',
'touchStartPreventDefault',
Expand Down
1 change: 1 addition & 0 deletions src/svelte/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const paramsList = [
'longSwipesMs',
'_followFinger',
'allowTouchMove',
'allowNextElementAtTheEnd',
'_threshold',
'touchMoveStopPropagation',
'touchStartPreventDefault',
Expand Down
5 changes: 5 additions & 0 deletions src/types/swiper-class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ interface Swiper extends SwiperClass<SwiperEvents> {
*/
allowTouchMove: boolean;

/**
* Do not hide element at the end of carousel - Carousel will go to start after click
*/
allowNextElementAtTheEnd: boolean;

/**
* !INTERNAL
*/
Expand Down
5 changes: 5 additions & 0 deletions src/types/swiper-options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ export interface SwiperOptions {
*/
allowTouchMove?: boolean;

/**
* Do not hide element at the end of carousel - Carousel will go to start after click
*/
allowNextElementAtTheEnd?: boolean | undefined;

/**
* Threshold value in px. If "touch distance" will be lower than this value then swiper will not move
*
Expand Down
1 change: 1 addition & 0 deletions src/vue/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const paramsList = [
'longSwipesMs',
'_followFinger',
'allowTouchMove',
'allowNextElementAtTheEnd',
'_threshold',
'touchMoveStopPropagation',
'touchStartPreventDefault',
Expand Down
4 changes: 4 additions & 0 deletions src/vue/swiper-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ declare const Swiper: DefineComponent<
type: BooleanConstructor;
default: undefined;
};
allowNextElementAtTheEnd: {
type: BooleanConstructor;
default: undefined;
};
threshold: { type: NumberConstructor; default: undefined };
touchMoveStopPropagation: {
type: BooleanConstructor;
Expand Down
1 change: 1 addition & 0 deletions src/vue/swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const Swiper = {
longSwipesMs: { type: Number, default: undefined },
followFinger: { type: Boolean, default: undefined },
allowTouchMove: { type: Boolean, default: undefined },
allowNextElementAtTheEnd: { type: Boolean, default: undefined },
threshold: { type: Number, default: undefined },
touchMoveStopPropagation: { type: Boolean, default: undefined },
touchStartPreventDefault: { type: Boolean, default: undefined },
Expand Down