From fd2548fb47e5f667ddbbbd481ca98b908b41b34d Mon Sep 17 00:00:00 2001 From: Becky Siegel Date: Fri, 3 Nov 2017 12:22:24 -0700 Subject: [PATCH] Consolidate button styles and update disabled Mostly general cleanup, also the following changes: - Disabled flat buttons will have a fully transparent background (before it was a partially transparent white background) - Disabled raised buttons have a (light) grey background and (darker) grey text. There is no difference in the disabled styling whether the button is primary or not. - Add loading as a property on gr-button, translate that into disabled on the paper-button, which removes some CSS rules. Bug: Issue 7496 Change-Id: Iae0564d099508827c8f13fbb943c6646d631ce1d --- .../elements/shared/gr-button/gr-button.html | 124 +++++++++--------- .../elements/shared/gr-button/gr-button.js | 13 ++ .../shared/gr-button/gr-button_test.html | 10 ++ 3 files changed, 86 insertions(+), 61 deletions(-) diff --git a/polygerrit-ui/app/elements/shared/gr-button/gr-button.html b/polygerrit-ui/app/elements/shared/gr-button/gr-button.html index 2246150654..483882ff58 100644 --- a/polygerrit-ui/app/elements/shared/gr-button/gr-button.html +++ b/polygerrit-ui/app/elements/shared/gr-button/gr-button.html @@ -24,6 +24,7 @@ limitations under the License. - \ No newline at end of file + diff --git a/polygerrit-ui/app/elements/shared/gr-button/gr-button.js b/polygerrit-ui/app/elements/shared/gr-button/gr-button.js index d552eb6825..b5a1d94467 100644 --- a/polygerrit-ui/app/elements/shared/gr-button/gr-button.js +++ b/polygerrit-ui/app/elements/shared/gr-button/gr-button.js @@ -27,6 +27,11 @@ value: false, reflectToAttribute: true, }, + loading: { + type: Boolean, + value: false, + reflectToAttribute: true, + }, tertiary: { type: Boolean, value: false, @@ -53,6 +58,10 @@ keydown: '_handleKeydown', }, + observers: [ + '_computeDisabled(disabled, loading)', + ], + behaviors: [ Gerrit.KeyboardShortcutBehavior, Gerrit.TooltipBehavior, @@ -77,6 +86,10 @@ this.setAttribute('tabindex', disabled ? '-1' : this._enabledTabindex); }, + _computeDisabled(disabled, loading) { + return disabled || loading; + }, + _handleKeydown(e) { if (this.modifierPressed(e)) { return; } e = this.getKeyboardEvent(e); diff --git a/polygerrit-ui/app/elements/shared/gr-button/gr-button_test.html b/polygerrit-ui/app/elements/shared/gr-button/gr-button_test.html index d78427bbca..c0ceb33ff5 100644 --- a/polygerrit-ui/app/elements/shared/gr-button/gr-button_test.html +++ b/polygerrit-ui/app/elements/shared/gr-button/gr-button_test.html @@ -51,6 +51,16 @@ limitations under the License. sandbox.restore(); }); + test('disabled is set by disabled or loading', () => { + assert.isFalse(element.$$('paper-button').disabled); + element.disabled = true; + assert.isTrue(element.$$('paper-button').disabled); + element.disabled = false; + assert.isFalse(element.$$('paper-button').disabled); + element.loading = true; + assert.isTrue(element.$$('paper-button').disabled); + }); + for (const eventName of ['tap', 'click']) { test('dispatches ' + eventName + ' event', () => { const spy = addSpyOn(eventName);