Skip to content

Commit 3719bb4

Browse files
committed
Put behind clamp option
1 parent 0d72cee commit 3719bb4

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/components/Carousel/Carousel.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ export const Carousel = defineComponent({
141141
})
142142

143143
Object.assign(config, fallbackConfig.value, newConfig)
144+
145+
// Validate itemsToShow
146+
if (!isAuto.value) {
147+
config.itemsToShow = getNumberInRange({
148+
val: Number(config.itemsToShow),
149+
max: props.clamp ? slidesCount.value : Infinity,
150+
min: 1,
151+
});
152+
}
144153
}
145154

146155
const handleResize = throttle(() => {
@@ -209,11 +218,6 @@ export const Carousel = defineComponent({
209218
min: minSlideIndex.value,
210219
})
211220
}
212-
213-
// Validate itemsToShow
214-
if (!isAuto.value) {
215-
config.itemsToShow = Math.max(Number(config.itemsToShow), 1);
216-
}
217221
}
218222

219223
const ignoreAnimations = computed<false | string[]>(() => {
@@ -848,7 +852,7 @@ export const Carousel = defineComponent({
848852
slidesCount,
849853
})
850854

851-
expose<CarouselExposed>({
855+
expose<CarouselExposed>(reactive({
852856
data,
853857
next,
854858
prev,
@@ -858,7 +862,7 @@ export const Carousel = defineComponent({
858862
updateSlideSize,
859863
updateSlidesData,
860864
...toRefs(provided),
861-
})
865+
}))
862866

863867
return () => {
864868
const slotSlides = slots.default || slots.slides

src/components/Carousel/carouselProps.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,7 @@ export const carouselProps = {
150150
default: DEFAULT_CONFIG.wrapAround,
151151
type: Boolean,
152152
},
153+
clamp: {
154+
type: Boolean,
155+
}
153156
}

src/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export type CarouselConfig = {
4949
touchDrag?: boolean
5050
transition?: number
5151
wrapAround?: boolean
52+
clamp?: boolean
5253
}
5354

5455
export type VueClass = string | Record<string, boolean> | VueClass[]

0 commit comments

Comments
 (0)