Merge "Remove iron-a11y-keys bindings from gr-button"

This commit is contained in:
Kasper Nilsson
2017-10-25 16:20:05 +00:00
committed by Gerrit Code Review
2 changed files with 20 additions and 7 deletions

View File

@@ -46,6 +46,7 @@
listeners: { listeners: {
tap: '_handleAction', tap: '_handleAction',
click: '_handleAction', click: '_handleAction',
keydown: '_handleKeydown',
}, },
behaviors: [ behaviors: [
@@ -58,10 +59,6 @@
tabindex: '0', tabindex: '0',
}, },
keyBindings: {
'space enter': '_handleCommitKey',
},
_handleAction(e) { _handleAction(e) {
if (this.disabled) { if (this.disabled) {
e.preventDefault(); e.preventDefault();
@@ -76,9 +73,15 @@
this.setAttribute('tabindex', disabled ? '-1' : this._enabledTabindex); this.setAttribute('tabindex', disabled ? '-1' : this._enabledTabindex);
}, },
_handleCommitKey(e) { _handleKeydown(e) {
e.preventDefault(); if (this.modifierPressed(e)) { return; }
this.click(); e = this.getKeyboardEvent(e);
// Handle `enter`, `space`.
if (e.keyCode === 13 || e.keyCode === 32) {
e.preventDefault();
e.stopPropagation();
this.click();
}
}, },
}); });
})(); })();

View File

@@ -67,6 +67,16 @@ limitations under the License.
MockInteractions.pressAndReleaseKeyOn(element, key); MockInteractions.pressAndReleaseKeyOn(element, key);
assert.isTrue(tapSpy.calledOnce); assert.isTrue(tapSpy.calledOnce);
}); });
test('dispatches no tap event with modifier on keycode ' + key, () => {
const tapSpy = sandbox.spy();
element.addEventListener('tap', tapSpy);
MockInteractions.pressAndReleaseKeyOn(element, key, 'shift');
MockInteractions.pressAndReleaseKeyOn(element, key, 'ctrl');
MockInteractions.pressAndReleaseKeyOn(element, key, 'meta');
MockInteractions.pressAndReleaseKeyOn(element, key, 'alt');
assert.isFalse(tapSpy.calledOnce);
});
} }
suite('disabled', () => { suite('disabled', () => {