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.36k stars 89 forks source link

Please add an option to make it behave like v3 #49

Open swey opened 7 years ago

swey commented 7 years ago

Hi guys,

first of all: Thanks for your great work!

We want to use the tool like in the old version, which means: As long there was no explicit input, the intent should also be used to fill data-whatinput.

Maybe it's the best to add an option for that?

I think of something like

import WhatInput from 'what-input';

WhatInput.init({ useIntentAsLongThereWasNoExplicitInput: true }); // Of course with a much better naming, was just for illustration purposes

Looking forward to your feedback!

ten1seven commented 7 years ago

Hi @swey, thanks for the feedback!

You should be able to still get the same response as v3 by using the data-whatintent attribute or querying whatInput.ask('loose'). That was my way of preserving the v3 functionality while moving forward with what I think is a better default (I had no idea the mousemove vs. no mousemove was going to be such a topic!).

If that's not what you were looking for, can you describe your use case so I can better understand how you're using it?

swey commented 7 years ago

Hi, data-whatintent does update on mousemove and touchmove even after there was an explicit input. The old version did update on move but only as long there was the first input.

To receive the behavior of v3, you have to do something like:

[data-whatinput="initial"][data-whatintent="keyboard"] .x:focus,
[data-whatinput="keyboard"] .x:focus {
    // 1. As long there was no input, the intention should be used
    // 2. As soon there as an input, that one should be used
}

(What we want to achieve: If someone did use the keyboard, the styling should not be changed by moving the mouse around.)

ten1seven commented 7 years ago

Hi @swey, I just released version 5 with some breaking changes to v4 and some updated logic to how input/intent behaves. It may still not be exactly what you're looking for, but I'd appreciate it if you'd give it a look.

swey commented 7 years ago

Thanks for your update, @ten1seven! I'll check it out the next days.