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

Add disableScroll option #413

Merged
merged 1 commit into from
Jun 23, 2019
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
11 changes: 2 additions & 9 deletions docs/welcome/css/welcome.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
html,
body {
height: 100%;
overflow: hidden;
}

body {
Expand Down Expand Up @@ -38,15 +36,10 @@ body {
}
}

.hero-scroll {
height: 100%;
overflow: auto;
-webkit-overflow-scrolling: touch;
width: 100%;
}

.hero-outer {
-webkit-box-sizing: border-box;
background-color: #62c462;
background-image: linear-gradient(-45deg, #62c462, #75beaa);
box-sizing: border-box;
display: table;
height: 100%;
Expand Down
56 changes: 28 additions & 28 deletions docs/welcome/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<link rel="apple-touch-icon" sizes="180x180" href="/shepherd/docs/assets/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/shepherd/docs/assets/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/shepherd/docs/assets/favicons/favicon-16x16.png" >
<link rel="icon" type="image/png" sizes="16x16" href="/shepherd/docs/assets/favicons/favicon-16x16.png">
<link rel="manifest" href="/shepherd/docs/assets/favicons/manifest.json">
<link rel="mask-icon" href="/shepherd/docs/assets/favicons/safari-pinned-tab.svg" color="#426170">
<link rel="shortcut icon" href="/shepherd/docs/assets/favicons/favicon.ico">
Expand All @@ -24,28 +24,29 @@
</head>

<body>
<div class="hero-scroll">
<div class="hero-outer">
<div class="hero-inner">
<div class="hero-welcome">
<h1>Shepherd</h1>
<div class="hero-outer">
<div class="hero-inner">
<div class="hero-welcome">
<h1>Shepherd</h1>

<h2>Guide your users through a tour of your app.</h2>
</div>
<h2>Guide your users through a tour of your app.</h2>
</div>

<div class="hero-including">
<h3>Including</h3>
<div class="hero-including">
<h3>Including</h3>

<script type="text/plain" class="language-markup" id="hero-including-code">
<script type="text/plain" class="language-markup" id="hero-including-code">
<link rel="stylesheet" href="/dist/css/shepherd-theme-default.css"/>
<script src="/dist/js/shepherd.min.js">&lt;/script>
</script>
</div>

<div class="hero-example">
<h3>Example</h3>

<pre id="hero-example-code">
</script>
</div>

<div class="hero-example">
<h3>Example</h3>

<pre id="hero-example-code">
<code class="language-javascript">
const tour = new Shepherd.Tour({
defaultStepOptions: {
Expand Down Expand Up @@ -76,18 +77,17 @@ <h3>Example</h3>
tour.start();
</code>
</pre>
</div>

<div class="hero-followup">
<p>
<a class="button star" href="https://github.com/shipshapecode/shepherd">★ on Github</a> &nbsp;&nbsp;
<a class="button" href="https://shipshapecode.github.io/shepherd/">View Docs</a> &nbsp;&nbsp;
<!--a class="button dark" href="https://eager.io/app/shepherd/install?utm_source=shepherd_docs_welcome">↓ Install</a-->
</p>
</div>
<div>
<img src="/shepherd/docs/welcome/sheep.svg"/>
</div>
</div>

<div class="hero-followup">
<p>
<a class="button star" href="https://github.com/shipshapecode/shepherd">★ on Github</a> &nbsp;&nbsp;
<a class="button" href="https://shipshapecode.github.io/shepherd/">View Docs</a> &nbsp;&nbsp;
<!--a class="button dark" href="https://eager.io/app/shepherd/install?utm_source=shepherd_docs_welcome">↓ Install</a-->
</p>
</div>
<div>
<img src="/shepherd/docs/welcome/sheep.svg"/>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions docs/welcome/js/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
scrollTo: { behavior: 'smooth', block: 'center' },
showCancelLink: true
},
disableScroll: true,
useModalOverlay: true
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"types": "src/shepherd.d.ts",
"module": "dist/js/shepherd.esm.js",
"dependencies": {
"body-scroll-lock": "^2.6.1",
"element-matches": "^0.1.2",
"lodash.defer": "^4.1.0",
"lodash.iselement": "^4.1.1",
Expand Down
9 changes: 9 additions & 0 deletions src/js/step.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isElement from 'lodash.iselement';
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock/lib/bodyScrollLock.es6.js';
import { isFunction, isString, isUndefined } from './utils/type-check';
import { Evented } from './evented.js';
import { bindAdvance, bindButtonEvents, bindCancelLink, bindMethods } from './utils/bind.js';
Expand Down Expand Up @@ -421,11 +422,19 @@ export class Step extends Evented {
scrollTo(scrollToOptions) {
const { element } = this.parseAttachTo();

enableBodyScroll();

if (isFunction(this.options.scrollToHandler)) {
this.options.scrollToHandler(element);
} else if (isElement(element)) {
element.scrollIntoView(scrollToOptions);
}

setTimeout(() => {
if (this.tour.options.disableScroll) {
disableBodyScroll();
}
}, 50);
}

/**
Expand Down
26 changes: 14 additions & 12 deletions src/js/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ import { Modal } from './modal.js';
import { Step } from './step.js';
import { bindMethods } from './utils/bind.js';
import tippy from 'tippy.js';
import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock/lib/bodyScrollLock.es6.js';
import { defaults as tooltipDefaults } from './utils/tooltip-defaults';

import {
cleanupSteps,
cleanupStepEventListeners
} from './utils/cleanup';

import {
getElementForStep
} from './utils/dom';

import {
toggleShepherdModalClass
} from './utils/modal';
import { cleanupSteps, cleanupStepEventListeners } from './utils/cleanup';
import { getElementForStep } from './utils/dom';
import { toggleShepherdModalClass } from './utils/modal';

/**
* Creates incremented ID for each newly created tour
Expand All @@ -42,6 +34,8 @@ export class Tour extends Evented {
/**
* @param {Object} options The options for the tour
* @param {Object} options.defaultStepOptions Default options for Steps ({@link Step#constructor}), created through `addStep`
* @param {boolean} options.disableScroll When set to true, will keep the user from scrolling with the scrollbar,
* mousewheel, arrow keys, etc. You may want to use this to ensure you are driving the scroll position with the tour.
* @param {Step[]} options.steps An array of Step instances to initialize the tour with
* @param {string} options.tourName An optional "name" for the tour. This will be appended to the the tour's
* dynamically generated `id` property -- which is also set on the `body` element as the `data-shepherd-active-tour` attribute
Expand Down Expand Up @@ -161,6 +155,10 @@ export class Tour extends Evented {
Shepherd.activeTour = null;
this._removeBodyAttrs();
this.trigger('inactive', { tour: this });

if (this.options.disableScroll) {
clearAllBodyScrollLocks();
}
}

/**
Expand Down Expand Up @@ -299,6 +297,10 @@ export class Tour extends Evented {
start() {
this.trigger('start');

if (this.options.disableScroll) {
disableBodyScroll();
}

this.currentStep = null;
this._setupActiveTour();
this.next();
Expand Down
10 changes: 5 additions & 5 deletions test/cypress/integration/test.acceptance.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,25 @@ describe('Shepherd Acceptance Tests', () => {
cy.get('.shepherd-element').should('have.class', 'test-more-defaults');
});

describe('scrollTo', () => {
describe('scrolling', () => {
it('scrollTo:true scrolls', () => {
const tour = setupTour(Shepherd, {
scrollTo: true
});
tour.start();
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('eq', 0);
cy.document().get('body').should('have.prop', 'scrollTop').and('eq', 0);
cy.contains('Next').click();
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('gt', 0);
cy.document().get('body').should('have.prop', 'scrollTop').and('gt', 0);
});

it('scrollTo:false does not scroll', () => {
const tour = setupTour(Shepherd, {
scrollTo: false
});
tour.start();
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('eq', 0);
cy.document().get('body').should('have.prop', 'scrollTop').and('eq', 0);
cy.contains('Next').click();
cy.get('[data-test-hero-scroll]').should('have.prop', 'scrollTop').and('eq', 0);
cy.document().get('body').should('have.prop', 'scrollTop').and('eq', 0);
});
});
});
Expand Down
11 changes: 2 additions & 9 deletions test/dummy/css/welcome.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 27 additions & 28 deletions test/dummy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicons/favicon-16x16.png" >
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicons/favicon-16x16.png">
<link rel="manifest" href="assets/favicons/manifest.json">
<link rel="mask-icon" href="assets/favicons/safari-pinned-tab.svg" color="#426170">
<link rel="shortcut icon" href="assets/favicons/favicon.ico">
Expand All @@ -26,28 +26,28 @@
</head>

<body>
<div class="hero-scroll" data-test-hero-scroll>
<div class="hero-outer">
<div class="hero-inner">
<div class="hero-welcome" data-test-hero-welcome>
<h1>Shepherd</h1>
<div class="hero-outer" data-test-hero-outer>
<div class="hero-inner">
<div class="hero-welcome" data-test-hero-welcome>
<h1>Shepherd</h1>

<h2>Guide your users through a tour of your app.</h2>
</div>
<h2>Guide your users through a tour of your app.</h2>
</div>

<div class="hero-including" data-test-hero-including>
<h3>Including</h3>
<div class="hero-including" data-test-hero-including>
<h3>Including</h3>

<script type="text/plain" class="language-markup" id="hero-including-code">
<script type="text/plain" class="language-markup" id="hero-including-code">
<link rel="stylesheet" href="/dist/css/shepherd-theme-default.css"/>
<script src="shepherd.min.js">&lt;/script>
</script>
</div>

<div class="hero-example">
<h3>Example</h3>
</script>
</div>

<div class="hero-example">
<h3>Example</h3>

<pre id="hero-example-code">
<pre id="hero-example-code">
<code class="language-javascript">
const tour = new Shepherd.Tour({
defaultStepOptions: {
Expand All @@ -66,18 +66,17 @@ <h3>Example</h3>
tour.start();
</code>
</pre>
</div>

<div class="hero-followup">
<p>
<a class="button star" href="https://github.com/shipshapecode/shepherd">★ on Github</a> &nbsp;&nbsp;
<a class="button" href="https://shipshapecode.github.io/shepherd/">View Docs</a> &nbsp;&nbsp;
<!--a class="button dark" href="https://eager.io/app/shepherd/install?utm_source=shepherd_docs_welcome">↓ Install</a-->
</p>
</div>
<div>
<img src="sheep.svg"/>
</div>
</div>

<div class="hero-followup">
<p>
<a class="button star" href="https://github.com/shipshapecode/shepherd">★ on Github</a> &nbsp;&nbsp;
<a class="button" href="https://shipshapecode.github.io/shepherd/">View Docs</a> &nbsp;&nbsp;
<!--a class="button dark" href="https://eager.io/app/shepherd/install?utm_source=shepherd_docs_welcome">↓ Install</a-->
</p>
</div>
<div>
<img src="sheep.svg"/>
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,11 @@ bluebird@3.5.5:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f"
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==

body-scroll-lock@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/body-scroll-lock/-/body-scroll-lock-2.6.1.tgz#3782ff37404886faaee366968ceee40c3964d8f2"
integrity sha512-fsDsq10+BJrk/+eGADqxspyZpGiKSh3dK8ByE6KuDK0REmPB99U05p1t9xVTAM9J6j9PJGm6W/W+HsCPnOFj+Q==

boolbase@^1.0.0, boolbase@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand Down