streamich / react-use

React Hooks — 👍
http://streamich.github.io/react-use
The Unlicense
41.98k stars 3.16k forks source link

feat: Support for Multiple Refs in useClickAway #2593

Open philipprus opened 2 months ago

philipprus commented 2 months ago

Description

  1. Updated useClickAway Hook: • The useClickAway hook was enhanced to accept either a single RefObject<HTMLElement | null> or an array of RefObject<HTMLElement | null>[]. • The hook now checks if the clicked element is outside of all the provided refs before triggering the onClickAway callback. This makes the hook more flexible and capable of handling multiple elements.
    1. Consolidated Storybook Example: • The Storybook demo was updated to demonstrate both the single ref and multiple refs usage within the same example. • The example includes: • A red box with a single ref that triggers the onClickAway callback when a click is detected outside of it. • A green and a blue box, each with its own ref, that together trigger a different onClickAway callback when a click is detected outside of either box. • This setup effectively showcases the new functionality of the useClickAway hook in a single, concise demonstration.

Example in SandBox

Go to sandbox

Type of change

Checklist