W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2014

[clipboard events] implicitly prevent default event action?

From: Hallvord R. M. Steen <hsteen@mozilla.com>
Date: Mon, 19 May 2014 06:50:35 -0700 (PDT)
To: public-webapps <public-webapps@w3.org>
Message-ID: <288101457.206059.1400507435050.JavaMail.zimbra@mozilla.com>
Hi,
there's a very annoying gotcha in the clipboard events spec: the "default action" of for example the copy event is to copy any selected text in the page (and do nothing if there is no selection). This remains the default action even if you use event.clipboardData.setData() and friends to modify the "payload" - it's a requirement to also call event.preventDefault() to make what you want to happen actually happen.

This extra "event.preventDefault()" is something I've personally forgotten to do several times - which is a bit embarrassing as I should be expected to know :-p. But worse than that is that regular web developers are likely to run into this pretty often too. I guess lots of people will struggle a bit here, and few of them will understand why it is even necessary.

So, is it necessary? IMO we can't change this basic default-action-of-event-is-copying-content approach, for backwards compatibility. But I guess we could say that the implementation itself cancels the default event if 

a) The event is script-generated and has a data payload (new ClipboardEvent('copy', {dataType:'text/plain', data:'Hi World'}))
b) Any event listener calls setData() or modifies the DataTransfer payload some other way

Thoughts?
-Hallvord
Received on Monday, 19 May 2014 13:51:03 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:24 UTC