Skip to content

Commit

Permalink
fix(akiran#2017): Dots state error when SlideToshow uses decimal valu…
Browse files Browse the repository at this point in the history
…e and infinite false.
  • Loading branch information
Vishwajeet committed Nov 22, 2023
1 parent 5558419 commit daa9868
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import React from "react";
import classnames from "classnames";
import { clamp } from "./utils/innerSliderUtils";

import { clamp, roundToDecimal } from "./utils/innerSliderUtils";
const getDotCount = spec => {
let dots;

Expand Down Expand Up @@ -46,14 +45,14 @@ export class Dots extends React.PureComponent {
const mouseEvents = { onMouseEnter, onMouseOver, onMouseLeave };
let dots = [];
for (let i = 0; i < dotCount; i++) {
let _rightBound = (i + 1) * slidesToScroll - 1;
let _rightBound = roundToDecimal((i + 1) * slidesToScroll - 1, 2);
let rightBound = infinite
? _rightBound
: clamp(_rightBound, 0, slideCount - 1);
let _leftBound = rightBound - (slidesToScroll - 1);
let _leftBound = roundToDecimal(rightBound - (slidesToScroll - 1), 2);
let leftBound = infinite
? _leftBound
: clamp(_leftBound, 0, slideCount - 1);
: clamp(_leftBound, 0, roundToDecimal(slideCount - slidesToShow, 2));

let className = classnames({
"slick-active": infinite
Expand Down
17 changes: 12 additions & 5 deletions src/utils/innerSliderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export function clamp(number, lowerBound, upperBound) {

export const safePreventDefault = event => {
const passiveEvents = ["onTouchStart", "onTouchMove", "onWheel"];
if(!passiveEvents.includes(event._reactName)) {
if (!passiveEvents.includes(event._reactName)) {
event.preventDefault();
}
}
};

export const getOnDemandLazySlides = spec => {
let onDemandSlides = [];
Expand Down Expand Up @@ -386,9 +386,12 @@ export const swipeMove = (e, spec) => {
let touchSwipeLength = touchObject.swipeLength;
if (!infinite) {
if (
(currentSlide === 0 && (swipeDirection === "right" || swipeDirection === "down")) ||
(currentSlide + 1 >= dotCount && (swipeDirection === "left" || swipeDirection === "up")) ||
(!canGoNext(spec) && (swipeDirection === "left" || swipeDirection === "up"))
(currentSlide === 0 &&
(swipeDirection === "right" || swipeDirection === "down")) ||
(currentSlide + 1 >= dotCount &&
(swipeDirection === "left" || swipeDirection === "up")) ||
(!canGoNext(spec) &&
(swipeDirection === "left" || swipeDirection === "up"))
) {
touchSwipeLength = touchObject.swipeLength * edgeFriction;
if (edgeDragged === false && onEdge) {
Expand Down Expand Up @@ -849,3 +852,7 @@ export const canUseDOM = () =>
window.document &&
window.document.createElement
);
export function roundToDecimal(number, decimalPlaces) {
const factor = Math.pow(10, decimalPlaces);
return Math.round(number * factor) / factor;
}

0 comments on commit daa9868

Please sign in to comment.