diff --git a/iron-a11y-keys-behavior.html b/iron-a11y-keys-behavior.html
index 807fe2d..be64729 100644
--- a/iron-a11y-keys-behavior.html
+++ b/iron-a11y-keys-behavior.html
@@ -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() {
@@ -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];
diff --git a/test/basic-test.html b/test/basic-test.html
index 8e50c92..fea60b6 100644
--- a/test/basic-test.html
+++ b/test/basic-test.html
@@ -30,6 +30,12 @@
+
+
+
+
+
+
@@ -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');
@@ -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);
+ });
+ });
+
});