Skip to content

Commit af80799

Browse files
committed
Add useKeyboard option to disable keyboard if needed
1 parent eeb7489 commit af80799

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Each instance will listen only once to any DOM listener. These listener are enab
4343
- unpreventTouchClass: Elements with this class won't `preventDefault` on touchMove. For instance, useful for a scrolling text inside a VirtualScroll-controled element. *Defaults to `vs-touchmove-allowed`*.
4444
- limitInertia: if true, will leverage [Lethargy](https://github.com/d4nyll/lethargy) to avoid everlasting scroll events (mostly on Apple Mouse, Trackpad, and free-wheel mouse). *Defaults to false.*
4545
- passive: if used, will use [passive events declaration](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners) for the wheel and touch listeners. Can be true or false. *Defaults to undefined.*
46+
- hasKeyDown: if true, allows to use arrows to navigate, and space to jump from one screen. *Defaults to true*
4647

4748
### License
4849
MIT.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "virtual-scroll",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "Smooth fake scroll using CSS transform",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function VirtualScroll(options) {
3333
keyStep: 120,
3434
preventTouch: false,
3535
unpreventTouchClass: 'vs-touchmove-allowed',
36-
limitInertia: false
36+
limitInertia: false,
37+
useKeyboard: true
3738
}, options);
3839

3940
if (this.options.limitInertia) this._lethargy = new Lethargy();
@@ -172,7 +173,7 @@ VirtualScroll.prototype._bind = function() {
172173
this.el.addEventListener('MSPointerMove', this._onTouchMove, true);
173174
}
174175

175-
if(support.hasKeyDown) document.addEventListener('keydown', this._onKeyDown);
176+
if(support.hasKeyDown && this.options.useKeyboard) document.addEventListener('keydown', this._onKeyDown);
176177
};
177178

178179
VirtualScroll.prototype._unbind = function() {
@@ -190,7 +191,7 @@ VirtualScroll.prototype._unbind = function() {
190191
this.el.removeEventListener('MSPointerMove', this._onTouchMove, true);
191192
}
192193

193-
if(support.hasKeyDown) document.removeEventListener('keydown', this._onKeyDown);
194+
if(support.hasKeyDown && this.options.useKeyboard) document.removeEventListener('keydown', this._onKeyDown);
194195
};
195196

196197
VirtualScroll.prototype.on = function(cb, ctx) {

0 commit comments

Comments
 (0)