How to have "onClickOutside" ?
See original GitHub issueHello here 👋
I have a specific use case where I want to display the Tippy component only on desktop views like following:
const defaultTippyProps: Omit<TippyProps, "content" | "children"> = {
animation: "shift-away-subtle",
arrow: true,
interactive: true,
trigger: "manual",
interactiveBorder: 10,
placement: "bottom-end",
delay: [0, 0],
duration: [200, 150],
maxWidth: 500,
appendTo: document.body,
sticky: true,
plugins: [sticky],
boundary: "viewport",
theme: "light",
distance: 24,
inertia: true,
}
const [showPopover, setShowPopover] = useState(false)
const open = () => setShowPopover(true)
const close = () => setShowPopover(false)
return isMobile ? (
<>
<MyMobileView content={content} visible={showPopover} .../>
</>
) : (
<Tippy
content={content}
{...defaultTippyProps}
visible={showPopover}
onHide={() => {
close()
}}
>
<span tabIndex={0} onClick={showPopover ? close : open}>
{children}
</span>
</Tippy>
)
The display of the tooltip depend on the showPopover
state. Here are my needs:
- When I click outside of the Tippy component, it should call
close()
to update the state, it works usingonHide/onHidden
here - When I resize the window, I should use
MyMobileView
so Tippy will be unmounted but I don’t want the state to be updated so it will display/openMyMobileView
but usingonHide
/onHidden
still update the state here
Ideally, I should use something like onClickOutside
instead of onHide
to handle my use case, do you see another way to do it with the current API?
Thanks by advance and feel free to ask if you need a PR or more informations 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:20 (17 by maintainers)
Top Results From Across the Web
react-onclickoutside - npm
An onClickOutside wrapper for React components. Latest version: 6.12.2, last published: 7 months ago. Start using react-onclickoutside in ...
Read more >react-onclickoutside examples - CodeSandbox
Learn how to use react-onclickoutside by viewing and forking example apps that make use of react-onclickoutside on CodeSandbox.
Read more >How to use the react-onclickoutside function in react ... - Snyk
To help you get started, we've selected a few react-onclickoutside examples, based on popular ways it is used in public projects.
Read more >How can I pass a ref to HOC that uses onClickOutside('react ...
I use onClickOutside('react-onclickoutside') for my HOC and I can't pass ref for this HOC, I have something like below and an error appears:...
Read more >How to detect a click outside a React component
First, we'll create a new React app to get started. ... Hence, the onClickOutside callback will be executed if a click event occurs...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Released, and I’ve added an example to the docs. Do you think we should make
hideOnClick: false
default if we detect thevisible
prop?Are you able to make a CodeSandbox demo?