-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add support for popper.js Virtual elements in Popover2 #4642
Comments
This would be an awesome feature to have - mouse following would be really useful when you have a large target. |
This comment was marked as spam.
This comment was marked as spam.
I agree that this would be a nice feature to add. In the meantime, I think you can implement such a feature yourself with Popover2/Tooltip2. Check out my quick version of this in this sandbox: |
@adidahiya Thanks for posting the example showing how to implement this with the current Popover component! One thing that would be really helpful is to retain the default behavior for keyboard navigation/focus behavior, i.e. when focusing the actual target (e.g. a button), the popover would be displayed and the position would be computed relative to the button’s position, but when hovering the button, it would position the popover relative to the cursor position. |
I believe my approach demonstrated in the code sandbox above will still work with Blueprint v5, but the public instance method to reposition the popover is now called
|
I don't know about repositioning and everything, but I got this to work with virtual elements using the <Popover
{…}
renderTarget={props => {
const { left, top } = …; // wherever you want to render the overlay (coming from state in my case)
const rect: DOMRect = {
width: 0,
height: 0,
x: left,
y: top,
left,
top,
right: left,
bottom: top,
toJSON() { return this; },
};
// The `renderTarget` in <ContextMenuPopover> uses a
// `<Portal><div className={Classes.CONTEXT_MENU_VIRTUAL_TARGET} style={contextMenu.targetOffset} ref={props.ref} /></Portal>`
// but this is too slow to mount (causing jumping context menus) and also is an unnecessary <div> anyway.
// We use a https://popper.js.org/docs/v2/virtual-elements/ instead, but augmented with some methods that Blueprint's <Popover> expects on its `targetRef` element
(props.ref as RefCallback<VirtualElement & Pick<HTMLElement, 'closest' | 'contains'>>)({
getBoundingClientRect() {
return rect;
},
closest() { return null; },
contains() { return false; },
contextElement: document.body,
});
return …; // whatever else you're rendering as the target, using the `props` except for the `ref`
}}
/> |
Feature request
https://popper.js.org/docs/v2/virtual-elements/
The text was updated successfully, but these errors were encountered: