Andarist / Andarist/use-onclickoutside

Add `capture` option for event handler?

Abierto
#7 5 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
496
Forks
27
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I faced the problem of inconsistent event handling. It appears in my SPA, when I navigate from route with component with dropdown that uses `useOnClickOutside` hook, and then navigate back. Component is being totally unmount during navigation.

When it is mounted back, `useOnClickOutside` adds event listener document again. I click on dropdown-list option, state of component changes, then list completely rerendered. And _somehow_ `mousedown` event for dropdown option fired before `mousedown` event on document. Between these to events dom node is being removed, so `onClickOutside` triggered.

I tried to provide `{ capture: true }` to `mousedown` event listener for document and now it's ok. So I think `capture` option should be provided by default, or at least via optional argument to hook. Is there any downside of this solution?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.