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: {
tap: '_handleAction',
click: '_handleAction',
keydown: '_handleKeydown',
},
behaviors: [
@@ -58,10 +59,6 @@
tabindex: '0',
},
keyBindings: {
'space enter': '_handleCommitKey',
},
_handleAction(e) {
if (this.disabled) {
e.preventDefault();
@@ -76,9 +73,15 @@
this.setAttribute('tabindex', disabled ? '-1' : this._enabledTabindex);
},
_handleCommitKey(e) {
e.preventDefault();
this.click();
_handleKeydown(e) {
if (this.modifierPressed(e)) { return; }
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);
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', () => {