Skip to content

Commit 0f95c7a

Browse files
authored
Merge pull request #2343 from akiran/fix-2076
Fixed #2076 click issue in Fade mode
2 parents 1a3f604 + d4595b0 commit 0f95c7a

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Test fix of #2076: Click on any slide in fade mode is triggering the click on last slide.
2+
3+
// Todo: Need to write the test in playwright (Couldn't trigger click on inner slide in fade mode with testing library)

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
testEnvironment: "jsdom",
3-
setupFilesAfterEnv: ["<rootDir>/test-setup.js"]
3+
setupFilesAfterEnv: ["<rootDir>/test-setup.js"],
4+
testPathIgnorePatterns: ["/node_modules/", "e2e-tests"]
45
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"webpack": "^4.21.0",
8181
"webpack-cli": "^3.1.2",
8282
"webpack-dev-server": "^3.1.9",
83-
"why-did-you-update": "^0.1.1"
83+
"why-did-you-update": "^0.1.1",
84+
"regenerator-runtime": "^0.14.1"
8485
},
8586
"dependencies": {
8687
"classnames": "^2.2.5",

src/track.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const getSlideStyle = spec => {
6767
style.left = -spec.index * parseInt(spec.slideWidth);
6868
}
6969
style.opacity = spec.currentSlide === spec.index ? 1 : 0;
70+
style.zIndex = spec.currentSlide === spec.index ? 999 : 998;
7071
if (spec.useCSS) {
7172
style.transition =
7273
"opacity " +
@@ -137,9 +138,7 @@ const renderSlides = spec => {
137138
// if slide needs to be precloned or postcloned
138139
if (spec.infinite && spec.fade === false) {
139140
let preCloneNo = childrenCount - index;
140-
if (
141-
preCloneNo <= getPreClones(spec)
142-
) {
141+
if (preCloneNo <= getPreClones(spec)) {
143142
key = -preCloneNo;
144143
if (key >= startIndex) {
145144
child = elem;
@@ -163,27 +162,27 @@ const renderSlides = spec => {
163162
);
164163
}
165164

166-
key = childrenCount + index;
167-
if (key < endIndex) {
168-
child = elem;
169-
}
170-
slideClasses = getSlideClasses({ ...spec, index: key });
171-
postCloneSlides.push(
172-
React.cloneElement(child, {
173-
key: "postcloned" + getKey(child, key),
174-
"data-index": key,
175-
tabIndex: "-1",
176-
className: classnames(slideClasses, slideClass),
177-
"aria-hidden": !slideClasses["slick-active"],
178-
style: { ...(child.props.style || {}), ...childStyle },
179-
onClick: e => {
180-
child.props && child.props.onClick && child.props.onClick(e);
181-
if (spec.focusOnSelect) {
182-
spec.focusOnSelect(childOnClickOptions);
183-
}
165+
key = childrenCount + index;
166+
if (key < endIndex) {
167+
child = elem;
168+
}
169+
slideClasses = getSlideClasses({ ...spec, index: key });
170+
postCloneSlides.push(
171+
React.cloneElement(child, {
172+
key: "postcloned" + getKey(child, key),
173+
"data-index": key,
174+
tabIndex: "-1",
175+
className: classnames(slideClasses, slideClass),
176+
"aria-hidden": !slideClasses["slick-active"],
177+
style: { ...(child.props.style || {}), ...childStyle },
178+
onClick: e => {
179+
child.props && child.props.onClick && child.props.onClick(e);
180+
if (spec.focusOnSelect) {
181+
spec.focusOnSelect(childOnClickOptions);
184182
}
185-
})
186-
);
183+
}
184+
})
185+
);
187186
}
188187
});
189188

test-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "@testing-library/jest-dom/extend-expect";
2+
import "regenerator-runtime/runtime";
23

34
//Fix for "matchMedia not present, legacy browsers require a polyfill jest" error
45
window.matchMedia =

0 commit comments

Comments
 (0)