Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use click outside to trigger also when previous click was on the target element #111

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions www/docs/Overlay.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,59 @@ function Example() {
);
}
```

## Scroll example

When the overlay is overflowing and contains a scrollbar, use the `rootCloseEvent="mouseup"` to ensure the overlay is closed when clicking the scrollbar and then outside of it.

```jsx live editor=collapse
import clsx from "clsx";
import { Overlay } from "@restart/ui";
import Button from "../src/Button";
import Tooltip from "../src/Tooltip";

function OverlayScrollTooltip() {
const [show, setShow] = useState(false);
const triggerRef = useRef(null);
const containerRef = useRef(null);

const toggleShow = () => {
setShow(!show);
};

return (
<div
className="flex flex-col items-center"
ref={containerRef}
>
<Button
className="mb-4"
id="overlay-toggle"
ref={triggerRef}
onClick={toggleShow}
>
Toggle a tooltip with a scrollbar
</Button>
<Overlay
show={show}
rootClose
rootCloseEvent="mouseup"
placement="left"
container={containerRef}
target={triggerRef}
onHide={toggleShow}
>
{(props, { arrowProps, popper }) => (
<Tooltip {...props} arrowProps={arrowProps} popper={popper}>
<div style={{ width: 150, height: 100, overflow: "auto"}}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hend rerit arcu
</div>
</Tooltip>
)}
</Overlay>
</div>
);
}

<OverlayScrollTooltip />;
```