Skip to content

Commit

Permalink
Merge pull request #64 from PolymerElements/unpressed-when-unfocused
Browse files Browse the repository at this point in the history
Button should not stay pressed when it becomes unfocused
  • Loading branch information
notwaldorf authored Apr 18, 2017
2 parents 4c85dc5 + 46cc9bd commit 4d79ebb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion iron-button-state.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},

observers: [
'_detectKeyboardFocus(focused)',
'_focusChanged(focused)',
'_activeChanged(active, ariaActiveAttribute)'
],

Expand All @@ -112,6 +112,14 @@
}
},

_focusChanged: function(focused) {
this._detectKeyboardFocus(focused);

if (!focused) {
this._setPressed(false);
}
},

_detectKeyboardFocus: function(focused) {
this._setReceivedFocusFromKeyboard(!this.pointerDown && focused);
},
Expand Down
10 changes: 10 additions & 0 deletions test/active-state.html
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4d79ebb

Please sign in to comment.