tiptap: Bubble menu doesn't position correctly if image has alignment
Description
When using bubble menu with image nodes and if there is image alignment functionality present which is achieved with float, the bubble menu above image is not positioned correctly.
Steps to reproduce the bug Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/tiptap-issue-template-forked-p5sny
- Click on image and see how the bubble menu is position in the middle of the editor
- Click on alignment button and change to left and see how the bubble menu is outside of editor
- Click on text nodes, bubble menu works as expetced
CodeSandbox I created a CodeSandbox to help you debug the issue: https://codesandbox.io/s/tiptap-issue-template-forked-p5sny
Expected behavior This should behave same as on text nodes.
Additional context
I did some investigation on the bubble menu and how it calculates position. It looks like the float changes the start and the end positioning of the node.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 32 (21 by maintainers)
Hello, I have a guess here:
.getBoundingClientRect()on it, this value will be enough for tippy to display properly.a proof of concept to fix this:
updatemethod to this:I’m not sure how can we get the selected element effectively , in my case I just get the element with
is-selectedclass I hope this will give some light to fix the issue 😃I think there are two issues here.
First, we have to provide an option to overwrite the logic for checking if a bubble menu should be shown or hidden. Basically these lines are doing it in the bubble menu plugin: https://github.com/ueberdosis/tiptap/blob/2c48bc09eac3f3ed65e01d7b7efd37984534db91/packages/extension-bubble-menu/src/bubble-menu-plugin.ts#L97-L104
So I’m thinking of adding something like this (would be available as prop for vue/react components as well):
It’s still too much code for overwriting in my eyes. Maybe there is some better way of doing this. Also the name
validateis bad I think. Anyone an idea for the naming?Second, there is probably an issue with calculating coords for atom nodes. I have to check that.
@zcuric this is because the getBoundingClientRect() is pointing to the wrapper itself, in react-views the wrapper does not have the style. as I commented above the
getBoundingClientRect()should be done on the first child and not on the wrapper. Also it would be a good idea to make this configurableI created a pull request for this in #3385
The only way I’m getting consistent results is with these changes:
@zcuric I’ve not tested your code but you can read about the reason of our custom
coordsAtPosmethod here:https://github.com/ueberdosis/tiptap/issues/215 https://github.com/ProseMirror/prosemirror-view/pull/47
That’s a cool solution! I tried to set
getReferenceClientRecton the bubble menu’stippy-optionsto keep from editing the original file but it’s set explicitly as we can see from the link you shared.If a solution that covers all use cases could be made in the bubble menu extension, that would be great - but if that’s not possible I wonder whether it could be re-jigged slightly so we can pass in our own
getReferenceClientRectfor each scenario.I also get inconsistent coordinates from coordsAtPos even when the image aren’t floated when the editor alignment is anything other than left (where I believe it is returning the correct left pos by happy accident).
I cloned the repo and logged/traced it, and just got a bit lost seeing exactly what was happening in coordsAtPos (first time I’m digging into this repo so I’m lacking some context for what all the bits being passed in are). While debugging,
sidewas coming out as left for one image node, and then right for another identically sized/positioned/etc. image.It appears to be a rework of the ProseMirror function and although the tiptap one has been updated more recently time-wise, it might have been based off an older version of the original? I found a few bubble menu position issues from the ProseMirror code while hunting this.
So, no actual help there - sorry! 🙈