Skip to content

Commit

Permalink
Fix autoPlay HOC swallowing third parameter of onChangeIndex (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-harrelson authored Feb 13, 2021
1 parent f0f114c commit 3142140
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/react-swipeable-views-utils/src/autoPlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function autoPlay(MyComponent) {
}
};

handleChangeIndex = (index, indexLatest) => {
handleChangeIndex = (index, indexLatest, meta) => {
// Is uncontrolled
if (this.props.index === undefined) {
this.setState({
Expand All @@ -91,7 +91,7 @@ export default function autoPlay(MyComponent) {
}

if (this.props.onChangeIndex) {
this.props.onChangeIndex(index, indexLatest);
this.props.onChangeIndex(index, indexLatest, meta);
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react-swipeable-views-utils/src/autoPlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('autoPlay', () => {
onChangeIndex: handleChangeIndex,
});
wrapper.find(Empty).simulate('changeIndex', 1, 0);
assert.deepEqual(handleChangeIndex.args, [[1, 0]]);
assert.deepEqual(handleChangeIndex.args, [[1, 0, undefined]]);
assert.strictEqual(wrapper.state().index, 0, 'should not update the state index');
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react-swipeable-views-utils/src/bindKeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function bindKeyboard(MyComponent) {
}
};

handleChangeIndex = (index, indexLatest) => {
handleChangeIndex = (index, indexLatest, meta) => {
// Is uncontrolled
if (this.props.index === undefined) {
this.setState({
Expand All @@ -128,7 +128,7 @@ export default function bindKeyboard(MyComponent) {
}

if (this.props.onChangeIndex) {
this.props.onChangeIndex(index, indexLatest);
this.props.onChangeIndex(index, indexLatest, meta);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('bindKeyboard', () => {
onChangeIndex: handleChangeIndex,
});
wrapper.find(Empty).simulate('changeIndex', 1, 0);
assert.deepEqual(handleChangeIndex.args, [[1, 0]]);
assert.deepEqual(handleChangeIndex.args, [[1, 0, undefined]]);
assert.strictEqual(wrapper.state().index, 0, 'should no update the state index');
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react-swipeable-views-utils/src/virtualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function virtualize(MyComponent) {
});
}

handleChangeIndex = (indexContainer, indexLatest) => {
handleChangeIndex = (indexContainer, indexLatest, meta) => {
const { slideCount, onChangeIndex } = this.props;

const indexDiff = indexContainer - indexLatest;
Expand All @@ -112,7 +112,7 @@ export default function virtualize(MyComponent) {
}

if (onChangeIndex) {
onChangeIndex(index, this.state.index);
onChangeIndex(index, this.state.index, meta);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe('virtualize', () => {
);

wrapper.find(Empty).simulate('changeIndex', 1, 0);
assert.deepEqual(handleChangeIndex.args, [[11, 10]]);
assert.deepEqual(handleChangeIndex.args, [[11, 10, undefined]]);
assert.strictEqual(wrapper.state().index, 10, 'should not update the state index');
});
});
Expand Down

0 comments on commit 3142140

Please sign in to comment.