Reputation: 15519
I'm trying to detect when a user presses return/enter in a chat box to send the message. How do I detect this for a paper-input
element?
Upvotes: 3
Views: 1281
Reputation: 24109
paper-input inherits from core-input
, which fires a change
event when the users hits enter/return or the element loses focus. If you don't care about the losing focus case (e.g only want the case where the user hits ENTER), you could check the document.activeElement
:
document.querySelector('paper-input').addEventListener('change', function(e) {
if (document.activeElement == this) {
console.log('ENTER hit on aper-input');
}
});
http://jsbin.com/godaqugacecu/1/edit
See http://www.polymer-project.org/docs/elements/core-elements.html#core-input.
Upvotes: 4