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

Commit

Permalink
Merge pull request #18 from PolymerElements/enable-selective-stop-pro…
Browse files Browse the repository at this point in the history
…pagation

Enable selective automatic stop propagation.
  • Loading branch information
cdata committed Oct 21, 2015
2 parents 8b85ed8 + 5093feb commit f271e5a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions iron-a11y-keys-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@
}
},

/**
* If true, this property will cause the implementing element to
* automatically stop propagation on any handled KeyboardEvents.
*/
stopKeyboardEventPropagation: {
type: Boolean,
value: false
},

_boundKeyHandlers: {
type: Array,
value: function() {
Expand Down Expand Up @@ -398,6 +407,10 @@
},

_onKeyBindingEvent: function(keyBindings, event) {
if (this.stopKeyboardEventPropagation) {
event.stopPropagation();
}

keyBindings.forEach(function(keyBinding) {
var keyCombo = keyBinding[0];
var handlerName = keyBinding[1];
Expand Down
31 changes: 31 additions & 0 deletions test/basic-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
</template>
</test-fixture>

<test-fixture id="NonPropagatingKeys">
<template>
<x-a11y-basic-keys stop-keyboard-event-propagation></x-a11y-basic-keys>
</template>
</test-fixture>

<test-fixture id="ComboKeys">
<template>
<x-a11y-combo-keys></x-a11y-combo-keys>
Expand Down Expand Up @@ -161,6 +167,15 @@
expect(keys.keyCount).to.be.equal(1);
});

test('allows propagation beyond the key combo handler', function() {
var keySpy = sinon.spy();
document.addEventListener('keydown', keySpy);

MockInteractions.pressEnter(keys);

expect(keySpy.callCount).to.be.equal(1);
});

suite('edge cases', function() {
test('knows that `spacebar` is the same as `space`', function() {
var event = new CustomEvent('keydown');
Expand Down Expand Up @@ -242,6 +257,22 @@
});
});

suite('stopping propagation automatically', function() {
setup(function() {
keys = fixture('NonPropagatingKeys');
});

test('does not propagate key events beyond the combo handler', function() {
var keySpy = sinon.spy();

document.addEventListener('keydown', keySpy);

MockInteractions.pressEnter(keys);

expect(keySpy.callCount).to.be.equal(0);
});
});

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

0 comments on commit f271e5a

Please sign in to comment.