Skip to content

Commit 0cbf77b

Browse files
committed
feat: enhance mouse drag functionality in Carousel with threshold option
1 parent 8411180 commit 0cbf77b

File tree

5 files changed

+5
-12
lines changed

5 files changed

+5
-12
lines changed

docs/config.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
| `itemsToScroll` | `number` | 1 | Number of slides to move when navigating. Useful for creating slide groups. |
1818
| `itemsToShow` | `number` \| 'auto' | 1 | Number of slides visible simultaneously. Use 'auto' for variable width slides. |
1919
| `modelValue` | `number` | 0 | Controls the active slide index. Can be used with v-model for two-way binding. |
20-
| `mouseDrag` | `boolean` | true | Enables/disables mouse drag navigation. |
21-
| `mouseDragThreshold` | `number` | 0.3 | Define a threshold for the drag distance required to trigger a slide transition. |
20+
| `mouseDrag` | `boolean` \| `object` | true | Enables/disables mouse drag navigation. When passed as an object, can contain a `threshold` property to control the drag distance required to trigger a slide transition. E.g. `{ threshold: 0.5 }`|
2221
| `mouseScroll` | `boolean` | false | Enables/disables mouse wheel scrolling for carousel navigation. |
2322
| `mouseScrollThreshold` | `number` | 10 | Controls the sensitivity threshold for mouse scrolling. Higher values require more scrolling. |
2423
| `pauseAutoplayOnHover` | `boolean` | false | When true, autoplay pauses while the mouse cursor is over the carousel. |

src/components/Carousel/Carousel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ export const Carousel = defineComponent({
415415
isReversed: isReversed.value,
416416
dragged: { x: deltaX, y: deltaY },
417417
effectiveSlideSize: effectiveSlideSize.value,
418-
threshold: config.mouseDragThreshold as number,
418+
threshold:
419+
typeof config.mouseDrag === 'object' ? (config.mouseDrag?.threshold ?? 0) : 0,
419420
})
420421

421422
activeSlideIndex.value = config.wrapAround

src/components/Carousel/carouselProps.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ export const carouselProps = {
105105
// toggle mouse dragging
106106
mouseDrag: {
107107
default: DEFAULT_CONFIG.mouseDrag,
108-
type: Boolean,
109-
},
110-
// control the threshold to trigger slide change with mouse drag
111-
mouseDragThreshold: {
112-
default: DEFAULT_CONFIG.mouseDragThreshold,
113-
type: Number,
108+
type: [Boolean, Object] as PropType<boolean | { threshold?: number }>,
114109
},
115110
// toggle mouse wheel scrolling
116111
mouseScroll: {

src/shared/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export const DEFAULT_CONFIG: CarouselConfig = {
5959
itemsToShow: 1,
6060
modelValue: 0,
6161
mouseDrag: true,
62-
mouseDragThreshold: 0.3,
6362
mouseScroll: false,
6463
mouseScrollThreshold: 10,
6564
pauseAutoplayOnHover: false,

src/shared/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export type CarouselConfig = {
4242
itemsToScroll: number
4343
itemsToShow: number | 'auto'
4444
modelValue?: number
45-
mouseDrag?: boolean
46-
mouseDragThreshold?: number
45+
mouseDrag?: boolean | { threshold?: number }
4746
mouseScroll?: boolean
4847
mouseScrollThreshold?: number
4948
pauseAutoplayOnHover?: boolean

0 commit comments

Comments
 (0)