Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/center infinite false #1920

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Resizable from "../examples/Resizable";
import UnevenSetsInfinite from "../examples/UnevenSetsInfinite";
import UnevenSetsFinite from "../examples/UnevenSetsFinite";
import CenterMode from "../examples/CenterMode";
import CenterModeInfiniteFalse from "../examples/CenterModeInfiniteFalse";
import FocusOnSelect from "../examples/FocusOnSelect";
import AutoPlay from "../examples/AutoPlay";
import AutoPlayMethods from "../examples/AutoPlayMethods";
Expand Down Expand Up @@ -45,6 +46,7 @@ export default class App extends React.Component {
<UnevenSetsInfinite />
<UnevenSetsFinite />
<CenterMode />
<CenterModeInfiniteFalse />
<FocusOnSelect />
<AutoPlay />
<AutoPlayMethods />
Expand Down
41 changes: 41 additions & 0 deletions examples/CenterModeInfiniteFalse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { Component } from "react";
import Slider from "../src/slider";

export default class CenterModeInfiniteFalse extends Component {
render() {
const settings = {
className: "center",
centerMode: true,
infinite: false,
centerPadding: "60px",
slidesToShow: 3,
initialSlide: 2,
speed: 500
};
return (
<div>
<h2>Center Mode</h2>
<Slider {...settings}>
<div>
<h3>1</h3>
</div>
<div>
<h3>2</h3>
</div>
<div>
<h3>3</h3>
</div>
<div>
<h3>4</h3>
</div>
<div>
<h3>5</h3>
</div>
<div>
<h3>6</h3>
</div>
</Slider>
</div>
);
}
}
54 changes: 54 additions & 0 deletions examples/__tests__/CenterModeInfiniteFalse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from "react";
import { mount } from "enzyme";
import { html as beautify_html } from "js-beautify";
import { clickNext } from "../../__tests__/testUtils";
import CenterModeInfiniteFalse from "../CenterModeInfiniteFalse";

describe("CenterModeInfiniteFalse Tests", () => {
test("Counting test", () => {
const slider = mount(<CenterModeInfiniteFalse />);
let totalSlides = slider.find(".slick-slide").length;
let clonedSlides = slider.find(".slick-cloned").length;
let activeSlides = slider.find(".slick-slide.slick-active").length;
expect(totalSlides).toEqual(6);
expect(clonedSlides).toEqual(0);
expect(activeSlides).toEqual(3);
expect(beautify_html(slider.html())).toMatchSnapshot();
});
test("Positioning test", () => {
const slider = mount(<CenterModeInfiniteFalse />);
let currentSlide = slider.find("div.slick-current");
let activeSlides = slider.find("div.slick-active");
expect(currentSlide.props()["data-index"]).toEqual(1);
expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
0,
1,
2
]);
expect(beautify_html(slider.html())).toMatchSnapshot();
});
test("Activity test", () => {
const slider = mount(<CenterModeInfiniteFalse />);
let currentSlide = slider.find("div.slick-current");
let activeSlides = slider.find("div.slick-active");
expect(currentSlide.props()["data-index"]).toEqual(1);
expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
0,
1,
2
]);

clickNext(slider);

currentSlide = slider.find("div.slick-current");
activeSlides = slider.find("div.slick-active");
expect(currentSlide.props()["data-index"]).toEqual(2);
expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
1,
2,
3
]);

expect(beautify_html(slider.html())).toMatchSnapshot();
});
});
163 changes: 163 additions & 0 deletions examples/__tests__/__snapshots__/CenterModeInfiniteFalse.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CenterModeInfiniteFalse Tests Activity test 1`] = `
"<div>
<h2>Center Mode</h2>
<div class=\\"slick-slider center slick-initialized\\" dir=\\"ltr\\"><button type=\\"button\\" data-role=\\"none\\" class=\\"slick-arrow slick-prev\\" style=\\"display: block;\\"> Previous</button>
<div class=\\"slick-list\\" style=\\"padding: 0px 60px;\\">
<div class=\\"slick-track\\" style=\\"width: -240px; opacity: 1; transform: translate3d(40px, 0px, 0px); transition: transform 500ms ease;\\">
<div data-index=\\"0\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>1</h3>
</div>
</div>
</div>
<div data-index=\\"1\\" class=\\"slick-slide slick-active\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>2</h3>
</div>
</div>
</div>
<div data-index=\\"2\\" class=\\"slick-slide slick-active slick-center slick-current\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>3</h3>
</div>
</div>
</div>
<div data-index=\\"3\\" class=\\"slick-slide slick-active\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>4</h3>
</div>
</div>
</div>
<div data-index=\\"4\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>5</h3>
</div>
</div>
</div>
<div data-index=\\"5\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>6</h3>
</div>
</div>
</div>
</div>
</div><button type=\\"button\\" data-role=\\"none\\" class=\\"slick-arrow slick-next\\" style=\\"display: block;\\"> Next</button>
</div>
</div>"
`;

exports[`CenterModeInfiniteFalse Tests Counting test 1`] = `
"<div>
<h2>Center Mode</h2>
<div class=\\"slick-slider center slick-initialized\\" dir=\\"ltr\\"><button type=\\"button\\" data-role=\\"none\\" class=\\"slick-arrow slick-prev\\" style=\\"display: block;\\"> Previous</button>
<div class=\\"slick-list\\" style=\\"padding: 0px 60px;\\">
<div class=\\"slick-track\\" style=\\"width: -240px; opacity: 1; transform: translate3d(0px, 0px, 0px);\\">
<div data-index=\\"0\\" class=\\"slick-slide slick-active\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>1</h3>
</div>
</div>
</div>
<div data-index=\\"1\\" class=\\"slick-slide slick-active slick-center slick-current\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>2</h3>
</div>
</div>
</div>
<div data-index=\\"2\\" class=\\"slick-slide slick-active\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>3</h3>
</div>
</div>
</div>
<div data-index=\\"3\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>4</h3>
</div>
</div>
</div>
<div data-index=\\"4\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>5</h3>
</div>
</div>
</div>
<div data-index=\\"5\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>6</h3>
</div>
</div>
</div>
</div>
</div><button type=\\"button\\" data-role=\\"none\\" class=\\"slick-arrow slick-next\\" style=\\"display: block;\\"> Next</button>
</div>
</div>"
`;

exports[`CenterModeInfiniteFalse Tests Positioning test 1`] = `
"<div>
<h2>Center Mode</h2>
<div class=\\"slick-slider center slick-initialized\\" dir=\\"ltr\\"><button type=\\"button\\" data-role=\\"none\\" class=\\"slick-arrow slick-prev\\" style=\\"display: block;\\"> Previous</button>
<div class=\\"slick-list\\" style=\\"padding: 0px 60px;\\">
<div class=\\"slick-track\\" style=\\"width: -240px; opacity: 1; transform: translate3d(0px, 0px, 0px);\\">
<div data-index=\\"0\\" class=\\"slick-slide slick-active\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>1</h3>
</div>
</div>
</div>
<div data-index=\\"1\\" class=\\"slick-slide slick-active slick-center slick-current\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>2</h3>
</div>
</div>
</div>
<div data-index=\\"2\\" class=\\"slick-slide slick-active\\" tabindex=\\"-1\\" aria-hidden=\\"false\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>3</h3>
</div>
</div>
</div>
<div data-index=\\"3\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>4</h3>
</div>
</div>
</div>
<div data-index=\\"4\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>5</h3>
</div>
</div>
</div>
<div data-index=\\"5\\" class=\\"slick-slide\\" tabindex=\\"-1\\" aria-hidden=\\"true\\" style=\\"outline: none; width: -40px;\\">
<div>
<div tabindex=\\"-1\\" style=\\"width: 100%; display: inline-block;\\">
<h3>6</h3>
</div>
</div>
</div>
</div>
</div><button type=\\"button\\" data-role=\\"none\\" class=\\"slick-arrow slick-next\\" style=\\"display: block;\\"> Next</button>
</div>
</div>"
`;
3 changes: 2 additions & 1 deletion src/arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class PrevArrow extends React.PureComponent {
if (
!this.props.infinite &&
(this.props.currentSlide === 0 ||
this.props.slideCount <= this.props.slidesToShow)
this.props.slideCount <= this.props.slidesToShow ||
(this.props.initialSlide && this.props.currentSlide === 1))
) {
prevClasses["slick-disabled"] = true;
prevHandler = null;
Expand Down
6 changes: 5 additions & 1 deletion src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class InnerSlider extends React.Component {
this.state = {
...initialState,
currentSlide: this.props.initialSlide,
targetSlide: this.props.initialSlide
? this.props.initialSlide
: initialState.targetSlide,
slideCount: React.Children.count(this.props.children)
};
this.callbackTimers = [];
Expand Down Expand Up @@ -685,7 +688,8 @@ export class InnerSlider extends React.Component {
"slideCount",
"slidesToShow",
"prevArrow",
"nextArrow"
"nextArrow",
"initialSlide"
]);
arrowProps.clickHandler = this.changeSlide;

Expand Down