Skip to content

Commit 748e1ec

Browse files
committed
fix: carousel
1 parent b094177 commit 748e1ec

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/machines/carousel/src/carousel.machine.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { add, clampValue, isObject, nextIndex, prevIndex, remove, uniq } from "@
55
import * as dom from "./carousel.dom"
66
import type { CarouselSchema } from "./carousel.types"
77

8-
const DEFAULT_SLIDES_PER_PAGE = 1
9-
const DEFAULT_SLIDES_PER_MOVE = "auto"
10-
118
export const machine = createMachine<CarouselSchema>({
129
props({ props }) {
1310
return {
@@ -16,8 +13,8 @@ export const machine = createMachine<CarouselSchema>({
1613
orientation: "horizontal",
1714
snapType: "mandatory",
1815
loop: false,
19-
slidesPerPage: DEFAULT_SLIDES_PER_PAGE,
20-
slidesPerMove: DEFAULT_SLIDES_PER_MOVE,
16+
slidesPerPage: 1,
17+
slidesPerMove: "auto",
2118
spacing: "0px",
2219
autoplay: false,
2320
allowMouseDrag: false,
@@ -85,12 +82,17 @@ export const machine = createMachine<CarouselSchema>({
8582
},
8683
},
8784

88-
// watch: {
89-
// slidesPerPage: ["setSnapPoints"],
90-
// slidesPerMove: ["setSnapPoints"],
91-
// page: ["scrollToPage", "focusIndicatorEl"],
92-
// orientation: ["setSnapPoints", "scrollToPage"],
93-
// },
85+
watch({ track, action, context, prop }) {
86+
track([() => prop("slidesPerPage"), () => prop("slidesPerMove")], () => {
87+
action(["setSnapPoints"])
88+
})
89+
track([() => context.get("page")], () => {
90+
action(["scrollToPage", "focusIndicatorEl"])
91+
})
92+
track([() => prop("orientation")], () => {
93+
action(["setSnapPoints", "scrollToPage"])
94+
})
95+
},
9496

9597
on: {
9698
"PAGE.NEXT": {

0 commit comments

Comments
 (0)