Skip to content

Commit

Permalink
Fixed akiran#2315
Browse files Browse the repository at this point in the history
  • Loading branch information
akiran committed Jan 25, 2024
1 parent 2420174 commit 9d96291
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailingComma: none
9 changes: 6 additions & 3 deletions src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import { InnerSlider } from "./inner-slider";
import json2mq from "json2mq";
import defaultProps from "./default-props";
import { canUseDOM } from "./utils/innerSliderUtils";
import { canUseDOM, filterSettings } from "./utils/innerSliderUtils";
const enquire = canUseDOM() && require("enquire.js");

export default class Slider extends React.Component {
Expand Down Expand Up @@ -198,14 +198,17 @@ export default class Slider extends React.Component {
if (settings === "unslick") {
const className = "regular slider " + (this.props.className || "");
return <div className={className}>{children}</div>;
} else if (newChildren.length <= settings.slidesToShow && !settings.infinite) {
} else if (
newChildren.length <= settings.slidesToShow &&
!settings.infinite
) {
settings.unslick = true;
}
return (
<InnerSlider
style={this.props.style}
ref={this.innerSliderRefHandler}
{...settings}
{...filterSettings(settings)}
>
{newChildren}
</InnerSlider>
Expand Down
25 changes: 20 additions & 5 deletions src/utils/innerSliderUtils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from "react";
import defaultProps from "../default-props";

export function clamp(number, lowerBound, upperBound) {
return Math.max(lowerBound, Math.min(number, 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 +387,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 +853,14 @@ export const canUseDOM = () =>
window.document &&
window.document.createElement
);

export const validSettings = Object.keys(defaultProps);

export function filterSettings(settings) {
return validSettings.reduce((acc, settingName) => {
if (settings.hasOwnProperty(settingName)) {
acc[settingName] = settings[settingName];
}
return acc;
}, {});
}

0 comments on commit 9d96291

Please sign in to comment.