Skip to content

Commit

Permalink
Fix the showElement bug in previous step
Browse files Browse the repository at this point in the history
  • Loading branch information
binrysearch committed Sep 8, 2024
1 parent aaedaf0 commit adf01be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/packages/tour/exitIntro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import removeShowElement from "./removeShowElement";
import { removeShowElement } from "./showElement";
import { Tour } from "./tour";

/**
Expand Down Expand Up @@ -28,6 +28,8 @@ export default async function exitIntro(
await tour.callback("exit")?.call(tour);

// set the step to default
// this would update the signal to the tour that the tour has ended
// and the corresponding components would be updated
tour.resetCurrentStep();

return true;
Expand Down
16 changes: 0 additions & 16 deletions src/packages/tour/removeShowElement.ts

This file was deleted.

20 changes: 18 additions & 2 deletions src/packages/tour/showElement.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { addClass } from "../../util/className";
import { TourStep } from "./steps";
import removeShowElement from "./removeShowElement";
import { Tour } from "./tour";
import getPropValue from "../../util/getPropValue";
import { queryElementsByClassName } from "../../util/queryElement";
import { removeClass } from "../../util/className";
import { showElementClassName } from "./classNames";

/**
* To set the show element
* This function set a relative (in most cases) position and changes the z-index
Expand All @@ -29,7 +32,7 @@ function setShowElement(targetElement: HTMLElement) {
*
* @api private
*/
export default async function _showElement(tour: Tour, step: TourStep) {
export async function showElement(tour: Tour, step: TourStep) {
tour.callback("change")?.call(tour, step.element);

//remove old classes if the element still exist
Expand All @@ -39,3 +42,16 @@ export default async function _showElement(tour: Tour, step: TourStep) {

await tour.callback("afterChange")?.call(tour, step.element);
}

/**
* To remove all show element(s)
*
* @api private
*/
export function removeShowElement() {
const elms = Array.from(queryElementsByClassName(showElementClassName));

for (const elm of elms) {
removeClass(elm, /introjs-[a-zA-Z]+/g);
}
}
10 changes: 8 additions & 2 deletions src/packages/tour/steps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TooltipPosition } from "../../packages/tooltip";
import showElement from "./showElement";
import { queryElement, queryElements } from "../../util/queryElement";
import cloneObject from "../../util/cloneObject";
import { Tour } from "./tour";
Expand All @@ -14,6 +13,7 @@ import {
dataTitleAttribute,
dataTooltipClass,
} from "./dataAttributes";
import { showElement } from "./showElement";

export type ScrollTo = "off" | "element" | "tooltip";

Expand Down Expand Up @@ -80,13 +80,19 @@ export async function nextStep(tour: Tour) {
* @api private
*/
export async function previousStep(tour: Tour) {
const currentStep = tour.getCurrentStep();
let currentStep = tour.getCurrentStep();

if (currentStep === undefined || currentStep <= 0) {
return false;
}

tour.decrementCurrentStep();
// update the current step after decrementing
currentStep = tour.getCurrentStep();

if (currentStep === undefined) {
return false;
}

const nextStep = tour.getStep(currentStep);
let continueStep: boolean | undefined = true;
Expand Down

0 comments on commit adf01be

Please sign in to comment.