Andarist / Andarist/use-onclickoutside

Add `capture` option for event handler?

未关闭
#7 5 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
496
派生
27
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。