Skip to content

Commit c34a2b7

Browse files
authored
Merge pull request #80 from HiDeoo/hd-onbeforechange-targetelement
Add `nextElement` to `onBeforeChange` callback
2 parents e72744b + c3aba09 commit c34a2b7

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22

3+
* The `onBeforeChange` callback now receives the `nextElement` as second parameter.
34
* Add missing `updateStepElement()` to the TypeScript type declarations.
45

56
## 0.5.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import { Steps, Hints } from 'intro.js-react';
7575
| `onBeforeExit` | Callback called before exiting the intro. <br> *If you want to prevent exiting the intro, you can return `false` in this callback (available since intro.js 0.2.7).* | Function <br> *(stepIndex)* | |
7676
| `onStart` | Callback called when the steps are enabled. | Function <br> *(stepIndex)* | |
7777
| `onChange` | Callback called when the current step is changed. | Function <br> *(nextStepIndex, nextElement)* | |
78-
| `onBeforeChange` | Callback called before changing the current step. <br> *If you want to prevent the transition to the next / previous step, you can return `false` in this callback (available since intro.js 2.8.0).* | Function <br> *(nextStepIndex)* | |
78+
| `onBeforeChange` | Callback called before changing the current step. <br> *If you want to prevent the transition to the next / previous step, you can return `false` in this callback (available since intro.js 2.8.0).* | Function <br> *(nextStepIndex, nextElement)* | |
7979
| `onAfterChange` | Callback called after changing the current step. | Function <br> *(newStepIndex, newElement)* | |
8080
| `onPreventChange` | Callback called if you prevented transitioning to a new step by returning `false` in `onBeforeChange`. | Function <br> *(stepIndex)* | |
8181
| `onComplete` | Callback called when all the steps are completed. | Function <br> *()* | |

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ declare module 'intro.js-react' {
7878
* If you want to prevent the transition to the next / previous step, you can return false in this callback
7979
* (available since intro.js 2.8.0).
8080
*/
81-
onBeforeChange?(nextStepIndex: number): void | false;
81+
onBeforeChange?(nextStepIndex: number, nextElement: Element): void | false;
8282
/**
8383
* Callback called after changing the current step.
8484
*/

src/components/Steps/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ export default class Steps extends Component {
134134
* Triggered before changing step.
135135
* @return {Boolean} Returning `false` will prevent the step transition.
136136
*/
137-
onBeforeChange = () => {
137+
onBeforeChange = nextElement => {
138138
if (!this.isVisible) {
139139
return true;
140140
}
141141

142142
const { onBeforeChange, onPreventChange } = this.props;
143143

144144
if (onBeforeChange) {
145-
const continueStep = onBeforeChange(this.introJs._currentStep);
145+
const continueStep = onBeforeChange(this.introJs._currentStep, nextElement);
146146

147147
if (continueStep === false && onPreventChange) {
148148
setTimeout(() => {

src/components/Steps/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@ describe('Steps', () => {
256256
expect(onBeforeChange).toHaveBeenCalledTimes(1);
257257
});
258258

259-
test('should call the onBeforeChange callback with the step number', () => {
259+
test('should call the onBeforeChange callback with the step number and the new element', () => {
260260
const onBeforeChange = jest.fn();
261261

262262
const wrapper = shallow(<Steps initialStep={0} steps={steps} onExit={() => {}} onBeforeChange={onBeforeChange} />, {
263263
lifecycleExperimental: true,
264264
});
265265
wrapper.setProps({ enabled: true });
266266

267-
expect(onBeforeChange).toHaveBeenCalledWith(1);
267+
expect(onBeforeChange).toHaveBeenCalledWith(1, null);
268268
});
269269

270270
test('should call the onPreventChange callback if onBeforeChange returned false to prevent transition', () => {

0 commit comments

Comments
 (0)