Skip to content

Commit 6dbabe4

Browse files
committed
feat: rename mouseScroll to mouseWheel and enhance wheel options in Carousel configuration
1 parent a43533f commit 6dbabe4

File tree

6 files changed

+63
-10
lines changed

6 files changed

+63
-10
lines changed

docs/config.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
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. |
2020
| `mouseDrag` | `boolean` \| `DragConfig` | true | Enables/disables mouse drag navigation. See [Drag Options](#drag-options) for configuration details. |
21-
| `mouseScroll` | `boolean` | false | Enables/disables mouse wheel scrolling for carousel navigation. |
22-
| `mouseScrollThreshold` | `number` | 10 | Controls the sensitivity threshold for mouse scrolling. Higher values require more scrolling. |
21+
| `mouseWheel` | `boolean` \| `WheelConfig` | false | Enables/disables mouse wheel scrolling for carousel navigation. See [Wheel Options](#wheel-options) for configuration details. |
2322
| `pauseAutoplayOnHover` | `boolean` | false | When true, autoplay pauses while the mouse cursor is over the carousel. |
2423
| `preventExcessiveDragging` | `boolean` | false | Limits dragging behavior at carousel boundaries for better UX. <Badge text="0.13.0" /> |
2524
| `slideEffect` | 'slide', 'fade' | 'slide' | Determines the transition effect between slides. |
@@ -55,6 +54,42 @@ Both `mouseDrag` and `touchDrag` properties accept either a boolean value or a `
5554
</template>
5655
```
5756

57+
## Wheel Options
58+
59+
The `mouseWheel` property accepts either a boolean value or a `WheelConfig` object with the following properties:
60+
61+
| Property | Type | Default | Description |
62+
|-------------|----------|---------|--------------------------------------------------------------------------------------------|
63+
| `threshold` | `number` | 10 | Controls the wheel movement threshold required to trigger a slide transition. Higher values require more scrolling to trigger a slide change. |
64+
65+
### Example
66+
67+
```vue
68+
<template>
69+
<Carousel
70+
:mouseWheel="{ threshold: 20 }"
71+
>
72+
<!-- Slides -->
73+
</Carousel>
74+
</template>
75+
```
76+
77+
## I18n
78+
79+
Available keys:
80+
81+
| Key | Defaults | Description |
82+
| --------------------- | -------------------------------------- | -------------------------------------------------------------------------- |
83+
| `ariaGallery` | "Gallery" | Used as the aria-label for the main carousel element, indicating purpose. |
84+
| `ariaNavigateToSlide` | "Navigate to slide {slideNumber}" | Sets title and aria-label for pagination buttons to select a slide. |
85+
| `ariaNextSlide` | "Navigate to next slide" | Sets title and aria-label for the "Next" navigation button. |
86+
| `ariaPreviousSlide` | "Navigate to previous slide" | Sets title and aria-label for the "Previous" navigation button. |
87+
| `iconArrowDown` | "Arrow pointing downwards" | Sets title and aria-label for the downward-pointing arrow SVG icon. |
88+
| `iconArrowLeft` | "Arrow pointing to the left" | Sets title and aria-label for the left-pointing arrow SVG icon. |
89+
| `iconArrowRight` | "Arrow pointing to the right" | Sets title and aria-label for the right-pointing arrow SVG icon. |
90+
| `iconArrowUp` | "Arrow pointing upwards" | Sets title and aria-label for the upward-pointing arrow SVG icon. |
91+
| `itemXofY` | "Item {currentSlide} of {slidesCount}" | Provides screen readers with the current slide's position in the sequence. |
92+
5893
## Slots
5994

6095
### Slides/Default
@@ -141,3 +176,16 @@ Available keys:
141176
| `iconArrowRight` | "Arrow pointing to the right" | Sets title and aria-label for the right-pointing arrow SVG icon. |
142177
| `iconArrowUp` | "Arrow pointing upwards" | Sets title and aria-label for the upward-pointing arrow SVG icon. |
143178
| `itemXofY` | "Item {currentSlide} of {slidesCount}" | Provides screen readers with the current slide's position in the sequence. |
179+
180+
### Example
181+
182+
```vue
183+
<template>
184+
<Carousel
185+
:mouseDrag="{ threshold: 0.5 }"
186+
:touchDrag="{ threshold: 0.7 }"
187+
>
188+
<!-- Slides -->
189+
</Carousel>
190+
</template>
191+
```

src/components/Carousel/Carousel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ export const Carousel = defineComponent({
861861
style: { transform: trackTransform.value },
862862
onMousedownCapture: config.mouseDrag ? handleDragStart : null,
863863
onTouchstartPassiveCapture: config.touchDrag ? handleDragStart : null,
864-
onWheel: config.mouseScroll ? handleScroll : null,
864+
onWheel: config.mouseWheel ? handleScroll : null,
865865
},
866866
output
867867
)

src/components/Carousel/carouselProps.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
SlideEffect,
1919
SnapAlign,
2020
DragConfig,
21+
WheelConfig,
2122
} from '@/shared'
2223

2324
export const carouselProps = {
@@ -109,9 +110,9 @@ export const carouselProps = {
109110
type: [Boolean, Object] as PropType<boolean | DragConfig>,
110111
},
111112
// toggle mouse wheel scrolling
112-
mouseScroll: {
113-
default: DEFAULT_CONFIG.mouseScroll,
114-
type: Boolean,
113+
mouseWheel: {
114+
default: DEFAULT_CONFIG.mouseWheel,
115+
type: [Boolean, Object] as PropType<boolean | WheelConfig>,
115116
},
116117
// control mouse scroll threshold
117118
mouseScrollThreshold: {

src/composables/useWheel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function useWheel(options: UseWheelOptions) {
2929
})
3030

3131
const handleScroll = throttle((event: Event): void => {
32-
if (!config.mouseScroll || sliding.value) {
32+
if (!config.mouseWheel || sliding.value) {
3333
return
3434
}
3535

@@ -39,7 +39,8 @@ export function useWheel(options: UseWheelOptions) {
3939
const wheelEvent = event as WheelEvent
4040

4141
// Add sensitivity threshold to prevent small movements from triggering navigation
42-
const threshold = config.mouseScrollThreshold as number // Default to 30 if undefined
42+
const threshold =
43+
typeof config.mouseWheel === 'object' ? (config.mouseWheel.threshold ?? 10) : 10
4344

4445
// Determine scroll direction
4546
const deltaY = Math.abs(wheelEvent.deltaY) > threshold ? wheelEvent.deltaY : 0

src/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const DEFAULT_CONFIG: CarouselConfig = {
5959
itemsToShow: 1,
6060
modelValue: 0,
6161
mouseDrag: true,
62-
mouseScroll: false,
62+
mouseWheel: false,
6363
mouseScrollThreshold: 10,
6464
pauseAutoplayOnHover: false,
6565
preventExcessiveDragging: false,

src/shared/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export type SnapAlign = (typeof SNAP_ALIGN_OPTIONS)[number]
3131
export type DragConfig = {
3232
threshold?: number
3333
}
34+
export type WheelConfig = {
35+
threshold?: number
36+
}
3437

3538
export type CarouselConfig = {
3639
autoplay?: number
@@ -47,7 +50,7 @@ export type CarouselConfig = {
4750
itemsToShow: number | 'auto'
4851
modelValue?: number
4952
mouseDrag?: boolean | DragConfig
50-
mouseScroll?: boolean
53+
mouseWheel?: boolean | WheelConfig
5154
mouseScrollThreshold?: number
5255
pauseAutoplayOnHover?: boolean
5356
preventExcessiveDragging: boolean

0 commit comments

Comments
 (0)