ten1seven / what-input

A global utility for tracking the current input method (mouse/pointer, keyboard or touch).
https://ten1seven.github.io/what-input
MIT License
1.35k stars 89 forks source link

Persist previous state when typing #2

Closed craigmdennis closed 9 years ago

craigmdennis commented 9 years ago

Not sure on the best approach but it would be nice to be able to still have 'mouse' set when typing in an input if the :focus was triggered by a click (or tap etc.).

craigmdennis commented 9 years ago

I've added the following:

body.addEventListener('keydown', function(event){
  if (event.keyCode == 9) { // Tab
    regularInput(event)
  }
});
craigmdennis commented 9 years ago

Ok, I see that I can probably do this with the API (coffeeScript)

# Set a custom 'typing' input
$('input').on 'input', ->
  whatInput.set('typing')
craigmdennis commented 9 years ago

Ok, that's still not as effective as only tracking the Tab keyCode. Suggestions?

ten1seven commented 9 years ago

Hi Craig,

This is a good feature that I missed! You caught me while I've been traveling since last Wednesday so I haven't had time to sit down and look. I'll be back at my desk tomorrow and let you know what I figure out.

ten1seven commented 9 years ago

Hey Craig,

I just created this pull request that ignores typing in form fields. I'd appreciate if you'd take a look and see what you think.

I was thinking of allowing developers to set a data attribute flag on the body to ignore this behavior. Something like data-whatinput-allowformtyping, but the default behavior would be to ignore form field typing. Thoughts?

craigmdennis commented 9 years ago

Looks good! I agree that it should ignore inputs by default. Not sure about data-whatinput-allowformtyping, seems a little verbose.