onclick() and onblur() ordering issue

前端 未结 6 1931
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 14:52

I have an input field that brings up a custom drop-down menu. I would like the following functionality:

  • When the user clicks anywhere outside the input field,
6条回答
  •  误落风尘
    2020-12-04 15:46

    I was having the exact same issue as you, my UI is designed exactly as you describe. I solved the problem by simply replacing the onClick for the menu items with an onMouseDown. I did nothing else; no onMouseUp, no flags. This resolved the problem by letting the browser automatically re-order based on the priority of these event handlers, without any additional work from me.

    Is there any reason why this wouldn't have also worked for you?

提交回复
热议问题