[FEAT REQ] Prefer focusin
and focusout
events over focus
and blur
#1201
Labels
focusin
and focusout
events over focus
and blur
#1201
Is your feature request related to a problem? Please describe.
I am implementing a copy button that on click will show a tooltip notifying you that you've copied some text. I've had difficulty with using the
blur
close event and narrowed it down to the fact it is not bubbling as expected to its parent.I have a setup similar to this:
After clicking the tooltip to open it is not possible to hide it on blur. This is because blur only fires on the button and does not bubble to its parent.
Describe the solution you'd like
I would like to see
focusin
andfocusout
events supported in favor/stead offocus
andblur
.focusin
andfocusout
event types support bubbling so my wrapper component can get those events.MDN reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/blur_event
Of note, React 17 made the change to prefer
focusin
andfocusout
: facebook/react#19606 (comment)Describe alternatives you've considered
I have some code to dispatch the right event at the wrapper level that gets me around this issue, but it looks pretty nasty:
One alternative is to move the
data-tooltip-id
tobutton
instead, but this could be difficult for a number of reasons. For me specifically, I am trying to be flexible and creating a generic tooltip component that lets a consumer specify whatever button/trigger inside. Ideally I'd like to avoid forcing the consumer to provide an ID through props or usingcloneElement
to set an ID.In my copy button scenario, I could set up the mouse events to handle close, but this doesn't solve the problem for keyboard users. On keyboard, if I tab to the button and hit enter, the tooltip will show and I cannot get rid of it by tabbing out.
Lastly, another difficulty is that some inputs could be wrapped by outer components/divs in their internal implementation, so blur wouldn't work for these.
Additional context
I've made a small sandbox to demo my particular issue. One button has the ID on the input and works as expected with blur. Another has the ID on the wrapper and doesn't work.
https://codesandbox.io/p/github/ReactTooltip/react-tooltip/csb-l3c433/draft/dank-snowflake?file=%2Fsrc%2FApp.tsx%3A31%2C23
The text was updated successfully, but these errors were encountered: