slate-editor | A complete rich text editor based on SlateJS framework | Editor library
kandi X-RAY | slate-editor Summary
kandi X-RAY | slate-editor Summary
A complete rich text editor based on SlateJS framework
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of slate-editor
slate-editor Key Features
slate-editor Examples and Code Snippets
Community Discussions
Trending Discussions on slate-editor
QUESTION
I am using the Material-UI Popper component (which in turn uses popper.js) to create a hovering toolbar. For the most part it is working well, except for one odd behavior:
- Select some text: the hovering toolbar appears above the text - as expected.
- Select any button in the toolbar: the appropriate action is performed. However the toolbar jumps to the top-left corner of the window. See below.
You can try out this behavior in my Storybook - just select some text and click on one of the "T" buttons.
The basic issue centers around positioning of the popper:
- When user selects some text, a fake virtual element is created and passed to the popper as an anchor element. Popper uses this
anchorEl
to position the hovering toolbar. So far so good. - When the user clicks on a button in the toolbar, the hovering toolbar jumps to the top-left of the window.
I am guessing this is happening because the anchor element is somehow lost when the underlying component re-renders. I don't know why, but this is just my theory. Can someone help me solve this issue?
The code that computes the anchorEl
sits inside a React useEffect()
. I have made sure that the dependency list for the useEffect
is accurate. I can see that when the toolbar jumps, the useEffect()
is NOT being called, which means that anchorEl
is not being recomputed. This leads me to believe that the toolbar should stay intact in its current position and not jump to (0,0). But that's not happening :-(.
Here's the useEffect()
code inside the toolbar component. You can find the full code in my repo. Any help would be much appreciated.
ANSWER
Answered 2020-Sep-04 at 22:02I believe your domRange
is no longer valid after toggleBlock does its work (due to dom nodes getting replaced), so getBoundingClientRect
is no longer returning anything meaningful.
You should be able to fix this by redoing the work of getting the range within the anchorEl's getBoundingClientRect
. Perhaps something like the following (I didn't try to execute it, so no guarantee that there aren't minor errors):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install slate-editor
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page