Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
remove keydown listener (#98)
Browse files Browse the repository at this point in the history
* remove keydown listeners

* add tests
  • Loading branch information
valdrinkoshi authored Aug 3, 2016
1 parent 8930a88 commit bd5091c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"iron-behaviors": "polymerelements/iron-behaviors#^1.0.0",
"iron-overlay-behavior": "polymerelements/iron-overlay-behavior#^1.0.0",
"iron-resizable-behavior": "polymerelements/iron-resizable-behavior#^1.0.0",
"neon-animation": "polymerelements/neon-animation#^1.0.0",
"iron-a11y-keys-behavior": "polymerelements/iron-a11y-keys-behavior#^1.0.0"
"neon-animation": "polymerelements/neon-animation#^1.0.0"
},
"devDependencies": {
"iron-component-page": "polymerelements/iron-component-page#^1.0.0",
Expand Down
14 changes: 0 additions & 14 deletions iron-dropdown-scroll-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
-->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">

<script>
(function() {
Expand Down Expand Up @@ -133,11 +132,6 @@

_unlockedElementCache: null,

_isScrollingKeypress: function(event) {
return Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(
event, 'pageup pagedown home end up left down right');
},

_hasCachedLockedElement: function(element) {
return this._lockedElementCache.indexOf(element) > -1;
},
Expand Down Expand Up @@ -206,8 +200,6 @@
document.addEventListener('touchstart', this._boundScrollHandler, true);
// Mobile devices can scroll on touch move:
document.addEventListener('touchmove', this._boundScrollHandler, true);
// Capture keydown to prevent scrolling keys (pageup, pagedown etc.)
document.addEventListener('keydown', this._boundScrollHandler, true);
},

_unlockScrollInteractions: function() {
Expand All @@ -216,7 +208,6 @@
document.removeEventListener('DOMMouseScroll', this._boundScrollHandler, true);
document.removeEventListener('touchstart', this._boundScrollHandler, true);
document.removeEventListener('touchmove', this._boundScrollHandler, true);
document.removeEventListener('keydown', this._boundScrollHandler, true);
},

/**
Expand All @@ -228,11 +219,6 @@
* @private
*/
_shouldPreventScrolling: function(event) {
// Avoid expensive checks if the event is not one of the observed keys.
if (event.type === 'keydown') {
// Prevent event if it is one of the scrolling keys.
return this._isScrollingKeypress(event);
}

// Update if root target changed. For touch events, ensure we don't
// update during touchmove.
Expand Down
19 changes: 19 additions & 0 deletions test/iron-dropdown-scroll-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@
grandChildOne.dispatchEvent(event);
expect(event.defaultPrevented).to.be.eql(false);
});

test('arrow keyboard events not prevented by manager', function() {
// Even if these events might cause scrolling, they should not be
// prevented because they might cause a11y issues (e.g. arrow keys
// used for navigating the content). iron-dropdown is capable of
// restoring the scroll position of the document if necessary.
var left = MockInteractions.keyboardEventFor('keydown', 37);
var up = MockInteractions.keyboardEventFor('keydown', 38);
var right = MockInteractions.keyboardEventFor('keydown', 39);
var down = MockInteractions.keyboardEventFor('keydown', 40);
grandChildOne.dispatchEvent(left);
grandChildOne.dispatchEvent(up);
grandChildOne.dispatchEvent(right);
grandChildOne.dispatchEvent(down);
expect(left.defaultPrevented).to.be.eql(false);
expect(up.defaultPrevented).to.be.eql(false);
expect(right.defaultPrevented).to.be.eql(false);
expect(down.defaultPrevented).to.be.eql(false);
});
});
});
});
Expand Down

0 comments on commit bd5091c

Please sign in to comment.