From 46cc9bd4c09a87650697584cc60dd52a352bccfd Mon Sep 17 00:00:00 2001 From: Keanu Lee Date: Wed, 28 Sep 2016 13:59:38 -0700 Subject: [PATCH] Button should not stay pressed when it becomes unfocused --- iron-button-state.html | 10 +++++++++- test/active-state.html | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/iron-button-state.html b/iron-button-state.html index 8114e2d..c5221b8 100644 --- a/iron-button-state.html +++ b/iron-button-state.html @@ -91,7 +91,7 @@ }, observers: [ - '_detectKeyboardFocus(focused)', + '_focusChanged(focused)', '_activeChanged(active, ariaActiveAttribute)' ], @@ -112,6 +112,14 @@ } }, + _focusChanged: function(focused) { + this._detectKeyboardFocus(focused); + + if (!focused) { + this._setPressed(false); + } + }, + _detectKeyboardFocus: function(focused) { this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); }, diff --git a/test/active-state.html b/test/active-state.html index 8735aaf..e1ed479 100644 --- a/test/active-state.html +++ b/test/active-state.html @@ -125,6 +125,16 @@ }); }); }); + + suite('on blur', function() { + test('the pressed property becomes false', function() { + MockInteractions.focus(activeTarget); + MockInteractions.down(activeTarget); + expect(activeTarget.hasAttribute('pressed')).to.be.eql(true); + MockInteractions.blur(activeTarget); + expect(activeTarget.hasAttribute('pressed')).to.be.eql(false); + }); + }); }); suite('without toggles attribute', function() {