forked from akiran/react-slick
-
Notifications
You must be signed in to change notification settings - Fork 25
fix: height style issue #107
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { Component } from "react"; | ||
import Slider from "../src/slider"; | ||
|
||
export default class VerticalModeWhenUnslick extends Component { | ||
render() { | ||
const settings = { | ||
dots: true, | ||
infinite: true, | ||
slidesToShow: 3, | ||
slidesToScroll: 1, | ||
vertical: true, | ||
verticalSwiping: true, | ||
beforeChange: function (currentSlide, nextSlide) { | ||
console.log("before change", currentSlide, nextSlide); | ||
}, | ||
afterChange: function (currentSlide) { | ||
console.log("after change", currentSlide); | ||
}, | ||
}; | ||
return ( | ||
<div> | ||
<h2>Vertical Mode When Unslick</h2> | ||
<Slider {...settings}> | ||
<div> | ||
<h3>1</h3> | ||
</div> | ||
<div> | ||
<h3>2</h3> | ||
</div> | ||
</Slider> | ||
</div> | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React from "react"; | ||
import { mount } from "enzyme"; | ||
|
||
import VerticalMode from "../VerticalMode"; | ||
import VerticalModeWhenUnslick from "../VerticalModeWhenUnslick"; | ||
import Slider from "../../src/slider"; | ||
|
||
describe("Vertical Mode", function () { | ||
it("should have 15 slides (3(preclone) + 6(actual) + 6(postclone))", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-slide").length).toEqual(15); | ||
}); | ||
it("should have 9 clone slides", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-cloned").length).toEqual(9); | ||
}); | ||
it("should have 3 active slide", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-slide.slick-active").length).toEqual(3); | ||
}); | ||
it("should have 6 dots", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-dots").children().length).toEqual(6); | ||
}); | ||
it("should have 1 active dot", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1); | ||
}); | ||
it("should have a prev arrow", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-prev").length).toEqual(1); | ||
}); | ||
it("should have a next arrow", function () { | ||
const wrapper = mount(<VerticalMode />); | ||
expect(wrapper.find(".slick-next").length).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe("Vertical Mode when Unslick", function () { | ||
// ref: https://github.com/enzymejs/enzyme/issues/1940 | ||
// fix the 'offsetHeight' to 100px | ||
const originalOffsetHeight = Object.getOwnPropertyDescriptor( | ||
HTMLElement.prototype, | ||
"offsetHeight" | ||
); | ||
beforeAll(() => { | ||
Object.defineProperty(HTMLElement.prototype, "offsetHeight", { | ||
configurable: true, | ||
value: 100, | ||
}); | ||
}); | ||
afterAll(() => { | ||
Object.defineProperty( | ||
HTMLElement.prototype, | ||
"offsetHeight", | ||
originalOffsetHeight | ||
); | ||
}); | ||
|
||
it("should render correct height when only child", function () { | ||
const wrapper = mount( | ||
<Slider vertical> | ||
<div> | ||
<h3>1</h3> | ||
</div> | ||
</Slider> | ||
); | ||
|
||
const slides = wrapper.find(".slick-slide"); | ||
const firstSlideHeight = slides.first().getDOMNode().offsetHeight; | ||
const totalHeight = parseInt(firstSlideHeight) * slides.length; | ||
const sliderTrackHeight = getComputedStyle( | ||
wrapper.find(".slick-track").getDOMNode() | ||
).height; | ||
|
||
expect(totalHeight).toEqual(parseInt(sliderTrackHeight)); | ||
}); | ||
|
||
it("should render correct height when unslick", function () { | ||
const wrapper = mount(<VerticalModeWhenUnslick />); | ||
|
||
const slides = wrapper.find(".slick-slide"); | ||
const firstSlideHeight = slides.first().getDOMNode().offsetHeight; | ||
const totalHeight = parseInt(firstSlideHeight) * slides.length; | ||
const sliderTrackHeight = getComputedStyle( | ||
wrapper.find(".slick-track").getDOMNode() | ||
).height; | ||
|
||
expect(totalHeight).toEqual(parseInt(sliderTrackHeight)); | ||
}); | ||
|
||
it("should have 2 slides (0(preclone) + 2(actual) + 0(postclone))", function () { | ||
const wrapper = mount(<VerticalModeWhenUnslick />); | ||
expect(wrapper.find(".slick-slide").length).toEqual(2); | ||
}); | ||
it("should have 0 clone slides", function () { | ||
const wrapper = mount(<VerticalModeWhenUnslick />); | ||
expect(wrapper.find(".slick-cloned").length).toEqual(0); | ||
}); | ||
it("should have 2 active slide", function () { | ||
const wrapper = mount(<VerticalModeWhenUnslick />); | ||
expect(wrapper.find(".slick-slide.slick-active").length).toEqual(2); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VerticalMode.js 例子中,Slider 子元素数量改为 1 ,由于设置了infinite: true,导致出现了克隆元素