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) {

why even do the feature detect at all?
Maybe instead actually show one of the `addEventListener` calls to make it a little more concrete?  Eg. could just write code something like:
```javascript
// setup event listeners for touch
target.addEventListener('touchstart', ontouchstart);
...
```

---
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#r73158649

Received on Tuesday, 2 August 2016 13:56:17 UTC