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

Possible bug: value persists "mouse" after pressed a key on a checkbox or a radio. #128

Open DmitryLen opened 1 year ago

DmitryLen commented 1 year ago

Because const formInputs = ['button', 'input', 'select', 'textarea'] includes an input tag, "whatintent" value persists "mouse" after pressed a key on a checkbox or a radio.

Possible solution: `

    const notFormInput =

    activeElem &&

    activeElem.nodeName &&

    (formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1 ||

      activeElem.type === "radio"

      || activeElem.type === "checkbox"

      || (activeElem.nodeName.toLowerCase() === "button" &&

        !checkClosest(activeElem, "form")));`
DmitryLen commented 1 year ago

data-whatintent becomes "keyboard" after pressed "Enter" button on IOS. Is this expected behaviour?

ten1seven commented 1 year ago

Hi @DmitryLen, thanks for bringing this issue up. Your first message sounds like the intended behavior when interacting with forms. I have that documented under interacting with forms. Can you take a look at that and let me know if you're seeing that or a bug? If, for your app, you want to detect all input changes, even when interacting with a form, you can use data-whatinput. data-whatintent "buffers" the input detection for mouse users when they interact with form elements.

The second issue you found, keyboard detection on iOS, seems like a bug. Did you see that in the current version of iOS so I can test?

DmitryLen commented 1 year ago

I've read the interacting with forms section. It says, the idea is mouse user's data-whatintent will be preserved as mouse while typing – @ten1seven , But checkboxes and radio share the same input tag as the text field, so "data-whatintent" value is preserved as mouse, after pressed a key on a checkbox or a radio.

The second issue you found, keyboard detection on iOS, seems like a bug. Did you see that in the current version of iOS so I can test? –@ten1seven , Sorry for no bug description. I can't reproduce this now on IOS 13 and IOS 16. This is not actual so far. May be this issue is specific HTML form markup dependent.

DmitryLen commented 1 year ago

@ten1seven ,

IOW, "data-whatintent" value is preserved as "mouse", when pressing a key on a checkbox or a radio, but this doesn't seem to be a "while typing" case. This happens, because checkboxes and radio share the same input tag as the text field.