Merge "For disabled buttons: enable pointer-events, and prevent tap event"

This commit is contained in:
Viktar Donich 2016-11-29 04:18:09 +00:00 committed by Gerrit Code Review
commit 09051e9659
4 changed files with 112 additions and 7 deletions

View File

@ -75,7 +75,6 @@ limitations under the License.
}
:host([disabled]) {
cursor: default;
pointer-events: none;
}
:host([loading]),
:host([loading][disabled]) {

View File

@ -29,6 +29,11 @@
},
},
listeners: {
'tap': '_handleAction',
'click': '_handleAction',
},
behaviors: [
Gerrit.KeyboardShortcutBehavior,
Gerrit.TooltipBehavior,
@ -43,6 +48,13 @@
'space enter': '_handleCommitKey',
},
_handleAction: function(e) {
if (this.disabled) {
e.preventDefault();
e.stopImmediatePropagation();
}
},
_disabledChanged: function(disabled) {
if (disabled) {
this._enabledTabindex = this.getAttribute('tabindex');

View File

@ -0,0 +1,93 @@
<!DOCTYPE html>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-button</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-button.html">
<test-fixture id="basic">
<template>
<gr-button></gr-button>
</template>
</test-fixture>
<script>
suite('gr-select tests', function() {
var element;
var sandbox;
var addSpyOn = function(eventName) {
var spy = sandbox.spy();
element.addEventListener(eventName, spy);
return spy;
};
setup(function() {
element = fixture('basic');
sandbox = sinon.sandbox.create();
});
teardown(function() {
sandbox.restore();
});
['tap', 'click'].forEach(function(eventName) {
test('dispatches ' + eventName + ' event', function() {
var spy = addSpyOn(eventName);
MockInteractions.tap(element);
assert.isTrue(spy.calledOnce);
});
});
// Keycodes: 32 for Space, 13 for Enter.
[32, 13].forEach(function(key) {
test('dispatches tap event on keycode ' + key, function() {
var tapSpy = sandbox.spy();
element.addEventListener('tap', tapSpy);
MockInteractions.pressAndReleaseKeyOn(element, key);
assert.isTrue(tapSpy.calledOnce);
})});
suite('disabled', function() {
setup(function() {
element.disabled = true;
});
['tap', 'click'].forEach(function(eventName) {
test('stops ' + eventName + ' event', function() {
var spy = addSpyOn(eventName);
MockInteractions.tap(element);
assert.isFalse(spy.called);
});
});
// Keycodes: 32 for Space, 13 for Enter.
[32, 13].forEach(function(key) {
test('stops tap event on keycode ' + key, function() {
var tapSpy = sandbox.spy();
element.addEventListener('tap', tapSpy);
MockInteractions.pressAndReleaseKeyOn(element, key);
assert.isFalse(tapSpy.called);
})});
});
});
</script>

View File

@ -27,6 +27,9 @@ limitations under the License.
// Elements tests.
[
'change-list/gr-change-list-item/gr-change-list-item_test.html',
'change-list/gr-change-list-view/gr-change-list-view_test.html',
'change-list/gr-change-list/gr-change-list_test.html',
'change/gr-account-entry/gr-account-entry_test.html',
'change/gr-account-list/gr-account-list_test.html',
'change/gr-change-actions/gr-change-actions_test.html',
@ -43,19 +46,14 @@ limitations under the License.
'change/gr-related-changes-list/gr-related-changes-list_test.html',
'change/gr-reply-dialog/gr-reply-dialog_test.html',
'change/gr-reviewer-list/gr-reviewer-list_test.html',
'change-list/gr-change-list/gr-change-list_test.html',
'change-list/gr-change-list-item/gr-change-list-item_test.html',
'change-list/gr-change-list-view/gr-change-list-view_test.html',
'core/gr-account-dropdown/gr-account-dropdown_test.html',
'core/gr-error-manager/gr-error-manager_test.html',
'core/gr-main-header/gr-main-header_test.html',
'core/gr-reporting/gr-reporting_test.html',
'core/gr-search-bar/gr-search-bar_test.html',
'diff/gr-diff/gr-diff-group_test.html',
'diff/gr-diff/gr-diff_test.html',
'diff/gr-diff-builder/gr-diff-builder_test.html',
'diff/gr-diff-comment/gr-diff-comment_test.html',
'diff/gr-diff-comment-thread/gr-diff-comment-thread_test.html',
'diff/gr-diff-comment/gr-diff-comment_test.html',
'diff/gr-diff-cursor/gr-diff-cursor_test.html',
'diff/gr-diff-highlight/gr-annotation_test.html',
'diff/gr-diff-highlight/gr-diff-highlight_test.html',
@ -63,6 +61,8 @@ limitations under the License.
'diff/gr-diff-processor/gr-diff-processor_test.html',
'diff/gr-diff-selection/gr-diff-selection_test.html',
'diff/gr-diff-view/gr-diff-view_test.html',
'diff/gr-diff/gr-diff-group_test.html',
'diff/gr-diff/gr-diff_test.html',
'diff/gr-patch-range-select/gr-patch-range-select_test.html',
'diff/gr-ranged-comment-layer/gr-ranged-comment-layer_test.html',
'diff/gr-selection-action-box/gr-selection-action-box_test.html',
@ -83,6 +83,7 @@ limitations under the License.
'shared/gr-alert/gr-alert_test.html',
'shared/gr-autocomplete/gr-autocomplete_test.html',
'shared/gr-avatar/gr-avatar_test.html',
'shared/gr-button/gr-button_test.html',
'shared/gr-change-star/gr-change-star_test.html',
'shared/gr-confirm-dialog/gr-confirm-dialog_test.html',
'shared/gr-cursor-manager/gr-cursor-manager_test.html',