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

Commit

Permalink
guard against null keyEventTarget (#48)
Browse files Browse the repository at this point in the history
* guard against null keyEventTarget

There are two calls to _listenKeyEventListeners() and one already guards against  null this.keyEventTarget. This change guards the call to _listenKeyEventListeners in attached from using a null keyEventTarget.

* Moving the keyEventTarget check

Moving the keyEventTarget check into _listenKeyEventListeners()

* test for fix to #49

* Removed blank line

* review nits
  • Loading branch information
dschuyler authored and valdrinkoshi committed Jun 24, 2016
1 parent 3636267 commit 5f77227
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion iron-a11y-keys-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,15 @@
_resetKeyEventListeners: function() {
this._unlistenKeyEventListeners();

if (this.isAttached && this.keyEventTarget) {
if (this.isAttached) {
this._listenKeyEventListeners();
}
},

_listenKeyEventListeners: function() {
if (!this.keyEventTarget) {
return;
}
Object.keys(this._keyBindings).forEach(function(eventName) {
var keyBindings = this._keyBindings[eventName];
var boundKeyHandler = this._onKeyBindingEvent.bind(this, keyBindings);
Expand Down
9 changes: 9 additions & 0 deletions test/basic-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@
});
});

suite('remove key behavior with null target', function () {
test('add and remove a iron-a11y-keys-behavior', function () {
var element = document.createElement('x-a11y-basic-keys');
element.keyEventTarget = null;
document.body.appendChild(element);
document.body.removeChild(element);
});
});

});
</script>
</body>
Expand Down

0 comments on commit 5f77227

Please sign in to comment.