Bug 14382

Summary: Enter key does not trigger onclick when focus on a button
Product: WebKit Reporter: Tore B. Krudtaa <krudtaa>
Component: AccessibilityAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WORKSFORME    
Severity: Normal CC: ap, aroben, jcraig, pgbakker, webkit
Priority: P2 Keywords: PlatformOnly
Version: 523.x (Safari 3)   
Hardware: PC   
OS: Windows XP   
Attachments:
Description Flags
HTML file that illustrates the bug. none

Description Tore B. Krudtaa 2007-06-25 04:42:51 PDT
Enter key does not trigger onclick when focus on a button

Example code below:
If I hit enter when focus is on the button in IE, Firefox, Opera then the onclick is triggered.... not so with Safari 3.0.2 beta on windows.
As I told in another bug... accesskey does not work on Safari for windows either.

Hope this is to be fixed to.

<button type="button" onclick="doSomething()" accesskey="D" style="background-color:transparent; border:0px; cursor:pointer;">
<img src="sysimg/date.gif" border="0" title="Find from date" align="absmiddle">
</button>
Comment 1 Paul 2007-07-25 01:32:22 PDT
Noticed this too, really a bad thing from an accessibility point of view....
Comment 2 Soap Blox 2007-07-27 16:54:07 PDT
(In reply to comment #1)
> Noticed this too, really a bad thing from an accessibility point of view....
> 

This is a bug... on windows for sure.  Don't have a mac, so I can't debug it myself, but others who do and use my software are complaining.

It's as if type="button" on Safari behaves has a type="submit", because it does call the onsubmit event when you hit enter on a type="button".

Comment 3 Soap Blox 2007-07-27 17:01:12 PDT
I guess I'm exposing my ignorance here, but even if it were behaving like a type="button", shouldn't the onclick still fire before the onsubmit?

Here's the code I'm using which isn't behaving correctly:

<input name="submitType" value="Preview" onclick="preview(this.form)" type="button">

I tab to the button, hit enter, and it goes right to the onsubmit event
Comment 4 andgarden 2007-07-27 17:26:44 PDT
I absolutely see this issue. It appears on Safari Mac, as well. Very annoying for those of us who don't want to switch contexts to enter a comment.
Comment 5 Soap Blox 2007-07-27 18:00:48 PDT
Created attachment 15713 [details]
HTML file that illustrates the bug.

Click on the button, you'll see an alert that says "I am an onclick".  Tab to the button, hit "return", you will see an alert that says "I am on onsubmit".

Using: Safari for Windows, 3.0.2 (522.13.1)
Comment 6 Dave Hyatt 2007-07-27 21:22:00 PDT
There is no bug on Mac.  This is really a Windows port issue.  

On the Mac, spacebar activates a button, and Enter activates the default button in dialogs.  The two are distinct. This is expected behavior to a Mac user.

On Windows this is not the case (Enter always activates the focused button, and only activates the default button if another button is not focused).
Comment 7 Soap Blox 2007-07-28 11:28:38 PDT
(In reply to comment #6)

Wow, on the PC, if i hit the space bar, I got an onclick.  Strange!  Never knew that.  Now I have to figure out how to set the default button.

hmmm...


Comment 8 David Kilzer (:ddkilzer) 2007-07-28 13:02:24 PDT
(In reply to comment #7)
> Wow, on the PC, if i hit the space bar, I got an onclick.  Strange!  Never knew
> that.  Now I have to figure out how to set the default button.

The default submit button is always the first <input type="submit"> within the <form></form> tags, although this may be browser dependent.  I don't think there's a way to set the default button, but I think it may be overridden an onsubmit handler (not sure).

Comment 9 Alexey Proskuryakov 2008-01-12 14:02:21 PST
If I'm not mistaken, on TOT both Mac and Windows ports work as this bug report requested. This may mean that we have a bug on Mac now.
Comment 10 Robert Blaut 2008-06-10 23:36:53 PDT
(In reply to comment #9)
> If I'm not mistaken, on TOT both Mac and Windows ports work as this bug report
> requested. This may mean that we have a bug on Mac now.
> 

The reported bug was fixed so I think we should close the bug report as fixed and eventually file a new report regarding Mac issue but, personally I don't think that the Mac behavior is buggy. Any other comments on this case?
Comment 11 James Craig 2013-04-15 16:05:05 PDT
Yes, it's expected that non-default buttons on Mac OS X are activated by pressing spacebar, not Return (or Enter). Given that this bug was for Windows, I'm closing it and cloning for the Mac regression.
Comment 12 James Craig 2013-04-15 16:13:49 PDT
That one is 114648
Comment 13 James Craig 2013-04-15 16:13:59 PDT
bug 114648