Skip to content
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

Allow exit animations to play before step tooltip disappears. #279

Merged
merged 3 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/js/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { forOwn, isString, isUndefined } from 'lodash';
* @private
*/
function _setupAdvanceOnHandler(selector) {
return (e) => {
return (event) => {
if (this.isOpen()) {
const targetIsEl = this.el && e.target === this.el;
const targetIsSelector = !isUndefined(selector) && e.target.matches(selector);
const targetIsEl = this.el && event.target === this.el;
const targetIsSelector = !isUndefined(selector) && event.target.matches(selector);

if (targetIsSelector || targetIsEl) {
this.tour.next();
}
Expand Down
24 changes: 13 additions & 11 deletions src/js/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,18 @@ export class Step extends Evented {
* Triggers `destroy` event
*/
destroy() {
if (this.tooltip) {
this.tooltip.destroy();
this.tooltip = null;
}

if (isElement(this.el) && this.el.parentNode) {
this.el.parentNode.removeChild(this.el);
delete this.el;
this.el = null;
}

if (this.tooltip) {
this.tooltip.destroy();
this.tooltip = null;
if (this.target) {
this.target.classList.remove('shepherd-enabled', 'shepherd-target');
}

this.trigger('destroy');
Expand All @@ -266,12 +270,6 @@ export class Step extends Evented {
hide() {
this.trigger('before-hide');

if (this.el) {
this.el.hidden = true;
// We need to manually set styles for < IE11 support
this.el.style.display = 'none';
}

document.body.removeAttribute('data-shepherd-step');

if (this.target) {
Expand All @@ -290,7 +288,11 @@ export class Step extends Evented {
* @return {boolean} True if the step is open and visible
*/
isOpen() {
return Boolean(this.el && !this.el.hidden);
return Boolean(
this.tooltip &&
RobbieTheWagner marked this conversation as resolved.
Show resolved Hide resolved
this.tooltip.state &&
this.tooltip.state.isVisible
);
}

/**
Expand Down
27 changes: 10 additions & 17 deletions src/js/tour.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFunction, isNumber, isString, isUndefined } from 'lodash';
import { isFunction, isNumber, isString, isUndefined, isEmpty } from 'lodash';
import { Evented } from './evented.js';
import { Step } from './step.js';
import { bindMethods } from './bind.js';
Expand Down Expand Up @@ -112,18 +112,12 @@ export class Tour extends Evented {
* @param {String} event The event name to trigger
*/
done(event) {
if (this.currentStep) {
this.currentStep.hide();
if (!isEmpty(this.steps)) {
this.steps.forEach((step) => step.destroy());
}

this.trigger(event);

if (Shepherd.activeTour) {
RobbieTheWagner marked this conversation as resolved.
Show resolved Hide resolved
Shepherd.activeTour.steps.forEach((step) => {
step.destroy();
});
}

Shepherd.activeTour = null;
document.body.classList.remove('shepherd-active');
this.trigger('inactive', { tour: this });
Expand Down Expand Up @@ -224,6 +218,10 @@ export class Tour extends Evented {
* @param {Boolean} forward True if we are going forward, false if backward
*/
show(key = 0, forward = true) {
if (this.currentStep) {
this.currentStep.hide();
}

this._setupActiveTour();

const step = isString(key) ? this.getById(key) : this.steps[key];
Expand Down Expand Up @@ -258,17 +256,12 @@ export class Tour extends Evented {
}

/**
* If we have a currentStep, the tour is active, so just hide the step and remain active.
* Otherwise, make the tour active.
* Make this tour "active"
* @private
*/
_setupActiveTour() {
if (this.currentStep) {
this.currentStep.hide();
RobbieTheWagner marked this conversation as resolved.
Show resolved Hide resolved
} else {
document.body.classList.add('shepherd-active');
this.trigger('active', { tour: this });
}
document.body.classList.add('shepherd-active');
this.trigger('active', { tour: this });

Shepherd.activeTour = this;
}
Expand Down
1 change: 0 additions & 1 deletion src/js/utils/tooltip-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export const defaults = {
arrow: true,
arrowTransform: 'scale(2)',
animation: 'fade',
delay: 200,
duration: 420,
flip: true,
animateFill: false, // https://atomiks.github.io/tippyjs/#animate-fill-option
Expand Down
12 changes: 10 additions & 2 deletions test/cypress/integration/element-targeting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ describe('Attaching tooltips to target elements in the DOM on each step', () =>
});

describe('Adding/Removing class names to the target of the current step', () => {
let tour;

beforeEach(() => {
tour = setupTour(Shepherd);
});

afterEach(() => {
tour.complete();
});

it('Adds the "shepherd-target" and "shepherd-enabled" classes upon showing a step', () => {
const tour = setupTour(Shepherd);
tour.start();

cy.get('.hero-welcome')
Expand All @@ -28,7 +37,6 @@ describe('Attaching tooltips to target elements in the DOM on each step', () =>
});

it('Removes the "shepherd-target" and "shepherd-enabled" upon hiding a step', () => {
const tour = setupTour(Shepherd);
tour.start();
tour.next();

Expand Down
11 changes: 0 additions & 11 deletions test/cypress/integration/test.acceptance.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,5 @@ describe('Shepherd Acceptance Tests', () => {
cy.get('.shepherd-step-element').should('have.length', 1);
});
});

describe('Cleaning up', () => {
RobbieTheWagner marked this conversation as resolved.
Show resolved Hide resolved
it('renders no steps when the tour completes', () => {
const tour = setupTour(Shepherd);

tour.start();
tour.complete();

cy.get('.shepherd-step-element').should('not.exist');
});
});
});
});
Loading