feat: Support for Multiple Refs in useClickAway #2593
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
• 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.
• 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
yarn test
)yarn lint
). Fix it withyarn lint:fix
in case of failure.yarn lint:types
).