0

I have an input field

[:input {:type "text"}]

and I need to detect when user presses an Esc key while editing that field. How do I do that?

pbkhrv
  • 647
  • 4
  • 11

1 Answers1

1

Add an :on-key-up (or :on-key-down) handler to the element:

[:input {:type "text"
         :on-key-up #(when (= 27 (.-which %))
                       (do-something-here))}]
pbkhrv
  • 647
  • 4
  • 11
  • Is 27 the key-code for escape? Edit: yes it is, keycodes mapping here: http://www.javascripter.net/faq/keycodes.htm – BWStearns Mar 31 '16 at 19:05
  • Yes. I use code similar to above in my app. Plus this http://stackoverflow.com/questions/1160008/which-keycode-for-escape-key-with-jquery – pbkhrv Mar 31 '16 at 19:07