Re: [w3c/touch-events] note about avoiding conditional "touch OR mouse/keyboard" event handling (#72)

> @@ -960,7 +960,26 @@ <h3 id="event-touchcancel">The <dfn class="event"><code>touchcancel</code></dfn>
>        </ol>           
>        </section>
>  
> -
> +      <section class="note">
> +      <p>Even if a user agent supports Touch Events, this does not necessarily mean that a touchscreen is the only input mechanism available to users. Particularly in the case of touch-enabled laptops, or traditional "touch only" devices (such as phones and tablets) with paired external input devices, users may use the touchscreen in conjunction with a trackpad, mouse or keyboard. For this reason, developers should avoid binding event listeners with "either touch or mouse/keyboard" conditional code, as this results in sites/application that become touch-exclusive, preventing users from being able to use any other input mechanism.</p>
> +<pre class="example"><code>
> +// conditional "touch OR mouse/keyboard" event binding
> +if ('ontouchstart' in window) {
> +  // set up event listeners for touch
> +} else {
> +  // set up event listeners for mouse/keyboard
> +}
> +</code></pre>
> +      <p>Instead, developers should handle different forms of input concurrently.</p>
> +<pre class="example"><code>
> +// concurrent "touch AND mouse/keyboard" event binding
> +if ('ontouchstart' in window) {

is there any perf downside to adding event listeners for touch even when no touch is present? otherwise yeah agree completely that the feature detect is irrelevant here.

suggestion of adding example addEventListeners is also a good one, will implement suggested changes later tonight :)

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/touch-events/pull/72/files/9faf80b27d03bdc65847bfb82bc851ebc203f3e6#r73170269

Received on Tuesday, 2 August 2016 14:53:54 UTC