Closed shrunyan closed 6 years ago
Hi @hubgit, just checking in to see if you had any thoughts on this solution.
Hi @shrunyan - this seems like a good approach, but I haven't had time to give it a proper try yet.
Do you need this to be merged so you can use it soon?
Yes I'll need to ship a solution in about 2 weeks. I can always fork and merge upstream if this lands.
I had a go at this slightly differently in https://github.com/hubgit/react-prosemirror/tree/floater using a positioned Floater
component to wrap the menu bar.
It seems to work quite well, but I'm not sure about the behaviour - should it always be displayed (which is what it currently does), or only when text is selected (which is what I was expecting)?
It might make sense to use react-popper
for the positioning, as it handles this kind of thing quite nicely.
I've merged #16 which adds a Floater
component for displaying a floating menu bar when there's a selection in the editor. Give that a try (it needs a few changes to the props and onChange handler as well) and see if it works for you, and feel free to open an issue if you'd like to see different behaviour.
Based on suggestions from pull/13 I've refactored to allow the
MenuBar
to accept afloating
Boolean prop which will tell it to handle determining menu position.I was unable to abstract away the need for providing the
view
prop which is a reference to the underlying Prosemirror editor. Because of how theEditor
component is handed to the render prop I can't determine away to get a reference to theview
. Tried a larger refactor but was unable to achieve the desired result without losing the ability to control your menu through therender
prop. Which is not an acceptable trade-off in my point of view, since that is arguably the most important feature of these components structure.Handled a few of the floating menu placement edge cases. I'm sure this logic and styling could be improved.
It should be noted the setup is a little cumbersome with requiring both the
view
andfloating
prop be provided in order to deliver the inline menu experience.If accepted closes https://github.com/hubgit/react-prosemirror/pull/13
Examples of menu placement.
Typical menu placement when there are now window collisions.
Menu determines it's to close to window right hand and switches direction.
Menu determines it's to close to the top and switches direction.