#13341 closed defect (fixed)
_onFocus is called before _onMouseDown
Reported by: | siqi | Owned by: | bill |
---|---|---|---|
Priority: | low | Milestone: | 1.7.6 |
Component: | Dijit | Version: | 1.7.0b1 |
Keywords: | Cc: | [email protected]… | |
Blocked By: | Blocking: |
Description (last modified by )
Open dijit/tests/form/test_CheckBox.html, add following code into dojo.addOnLoad:
dojo.connect(dijit.byId("cb1"), "_onMouseDown", function(){console.log("mouseDown");}); dojo.connect(dijit.byId("cb1"), "_onFocus", function(){console.log("focus");});
Click on the checkbox, it prints "focus" thand "mouseDown" in the console.
Is it what we expected? I think "_onMouseDown" should be called before "_onFocus", in the same order as the native events 'mousedown' -> 'focus' -> 'mouseup' -> 'click'.
Change History (21)
comment:1 follow-up: 2 Changed 11 years ago by
Priority: | high → low |
---|---|
severity: | critical → minor |
comment:2 Changed 11 years ago by
Replying to bill:
This is expected, due to how the focus manager is written: it catches the onmousedown event before cb1 does, and then calls cb1._onFocus(). Note that _onFocus is misnamed as it doesn't correspond exactly to DOM focus events, but too late to change the name now.
You could always connect to "onfocus" on cb1.focusNode to get the behavior you want.
Oh yes, you're right. The work around works well. :-)
comment:3 follow-up: 4 Changed 11 years ago by
Component: | Dijit - Form → Dijit |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
OK great. We could make _onFocus() occur after _onMouseDown() with a setTimeout(), but we try to avoid setTimeout() whenever possible. Other than that I don't know a way to change the order of those events. So I'm going to mark this as wontfix for now, directing people to use that workaround.
comment:4 Changed 11 years ago by
Replying to bill:
OK great. We could make _onFocus() occur after _onMouseDown() with a setTimeout(), but we try to avoid setTimeout() whenever possible. Other than that I don't know a way to change the order of those events. So I'm going to mark this as wontfix for now, directing people to use that workaround.
Exactly, setTimeout() is always not what we want....:-)
comment:5 Changed 10 years ago by
Description: | modified (diff) |
---|
comment:8 Changed 10 years ago by
Milestone: | tbd → future |
---|---|
Resolution: | wontfix |
Status: | closed → reopened |
I suppose if we did have a setTimeout(), it could be to trigger the so-called _onFocus() event when there was a mousedown event which wasn't followed immediately by a focus event (such as the case of clicking the non-focusable up/down arrows on a spinner). I.e. setup a timer on mousedown, but clear it onfocus.
Perhaps since this has come up a number of times I should do that. I'll reopen this to consider.
Alternately, perhaps the focus manager should just ignore mouse events, and clicking the up/down arrows on a spinner shouldn't cause it to focus.
PS: Need to think about _onBlur() events too though. Ideally clicking the arrows on a focused spinner shouldn't cause an _onBlur() call, since that would make the value reformat from 12345 to 12,345. Or worse yet, an _onBlur() followed after 0ms by another _onFocus().
Also consider stuff like iOS where the mousedown, mouseup, and click events all occur together. We wouldn't want an _onFocus() call to occur after the click event, as it might lead to problems like an onclick listener opening a TooltipDialog and then the Button._onFocus() call immediately closing that TooltipDialog.
comment:10 Changed 9 years ago by
Milestone: | future → 1.9 |
---|---|
Owner: | changed from Douglas Hays to bill |
Status: | reopened → assigned |
comment:17 Changed 8 years ago by
[30957] backported to 1.8 in e2b992b720df9936af690e08de1a76c299f38613.
comment:21 Changed 8 years ago by
Milestone: | 1.9 → 1.7.6 |
---|
This is expected, due to how the focus manager is written: it catches the onmousedown event before cb1 does, and then calls cb1._onFocus(). Note that _onFocus is misnamed as it doesn't correspond exactly to DOM focus events, but too late to change the name now.
You could always connect to "onfocus" on cb1.focusNode to get the behavior you want.