W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2009

Re: [whatwg] focus change inside keypress event handler

From: Jacob Rossi <rossi@gatech.edu>
Date: Wed, 28 Oct 2009 10:57:43 -0400
Message-ID: <b1dbfad70910280757o489dabc3re543b1df294b65a@mail.gmail.com>
To: shadow2531@gmail.com, t.broyer@gmail.com
Cc: whatwg@whatwg.org, www-dom@w3.org
On Wed, Oct 28, 2009 at 2:43 AM, Michael A. Puls II
<shadow2531@gmail.com<shadow2531@gmail.com?Subject=Re%3A%20%5Bwhatwg%5D%20focus%20change%20inside%20keypress%20event%20handler&In-Reply-To=%253Ca9699fd20910280201h3c7990a1s7cb9a7e5dc2c60c1%40mail.gmail.com%253E&References=%253Ca9699fd20910280201h3c7990a1s7cb9a7e5dc2c60c1%40mail.gmail.com%253E>>
wrote:
> (CCing DOM list just in case anyone there has any comments)
>
> With:
>
> <p><input onkeypress="this.nextSibling.focus()"><input></p>
>
> , if you type a character in the first field, should the character be
> entered in the second field or the first?
>
> In Firefox and Safari, it's the first field. In IE and Opera, it's the
> second.
[...]
> I do think FF and Safari's way makes more sense and I think most will
agree.

The keypress event is similar to textInput.  Their intent is to indicate
when character data has been entered. textInput is more powerful and
captures character input from a number of input sources (keyboard, IME,
voice, etc). In both cases, I would consider the default action to be the
insertion of the characters into the DOM. For *most* events, the default
action isn't performed until after event dispatch. Accordingly, I would
expect that calling focus() during the dispatch of the keypress (or
textInput) event would result in moving the cursor prior to the character
data being inserted (because events are synchronous). Thus I think it makes
most sense for the character to appear in the second input box.

Another reason why this should be the case is what happens when you cancel
the default action (call preventDefault() ). Canceling a textInput or
keypress event should prevent the character from being inserted. So that's
further evidence that the character insertion should happen after dispatch
of the event.

--Jacob
Received on Wednesday, 28 October 2009 14:58:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:04 GMT