From ae0c6e5c7e067f20c261cbacd3078a1c343316b2 Mon Sep 17 00:00:00 2001 From: Keanu Lee Date: Tue, 18 Apr 2017 16:10:11 -0700 Subject: [PATCH] Remove ripple when element becomes unfocused --- paper-button-behavior.html | 7 +++++++ test/paper-button-behavior.html | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/paper-button-behavior.html b/paper-button-behavior.html index c4d1330..d6690e9 100644 --- a/paper-button-behavior.html +++ b/paper-button-behavior.html @@ -84,6 +84,13 @@ if (this.hasRipple()) { this._ripple.uiUpAction(); } + }, + + _focusChanged: function(focused) { + Polymer.IronButtonStateImpl._focusChanged.call(this, focused); + if (!focused && this.hasRipple()) { + this._ripple.uiUpAction(); + } } }; diff --git a/test/paper-button-behavior.html b/test/paper-button-behavior.html index ff85925..d245fef 100644 --- a/test/paper-button-behavior.html +++ b/test/paper-button-behavior.html @@ -106,6 +106,30 @@ } }); }); + + test('focus changed', function(done) { + const SPACE_KEY_CODE = 32; + var ripple; + MockInteractions.focus(button); + + assert.ok(button.hasRipple()); + + ripple = button.getRipple(); + MockInteractions.keyDownOn(button, SPACE_KEY_CODE); + + assert.equal(ripple.ripples.length, 1); + + MockInteractions.blur(button); + + var transitionEndCalled = false; + ripple.addEventListener('transitionend', function() { + if (!transitionEndCalled) { + transitionEndCalled = true; + assert.equal(ripple.ripples.length, 0); + done(); + } + }); + }); });