One more possibility: 2 events are different in "isTrusted" value.
I just ran into this problem.
After doing a little debug, I found that the 2 events are different in "isTrusted" value.
Conditions:
I called element.click()
in anotherInputBox's "keydown" event handler.
After a keydown, element
receive a pair of events, which one is "isTrusted:true", another is "isTrusted:false"
According to MDN (https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted), isTrusted
is used to determine whether the event is user-triggered(true) or programatically-fired(false).
Solutions:
a. Handle double fire better and block the second event by state in your use case
b. Choose whether you want user-triggered or programatically-fired
c. Do not use click(). Make the click handler a function, and both call the function from event handler directly