konstantinmuenster / lexical-floating-menu

Designed for @lexical/react. Headless & fully-customizable.
https://lexical-floating-menu.vercel.app
MIT License
30 stars 1 forks source link

fix menu position for scrollable editor content #2

Closed konstantinmuenster closed 1 year ago

konstantinmuenster commented 1 year ago

if the editor content has a fixed height and overflow:scroll, the menu should stick at the selection position

https://github.com/konstantinmuenster/lexical-floating-menu/assets/46243719/d2e55c44-a198-462e-88f0-743dc6ae95e8

konstantinmuenster commented 1 year ago

Just had a look at it again. The menu actually sticks to the selection if the anchor element is correctly specified.

If, for example, your editor wrapper has a fixed height, you can use the element property to set this scrollable element as the anchor.

  <div id="editor-wrapper" style={{ maxHeight: '400px', overflowY: 'scroll' }}>
    <LexicalComposer>
      <RichTextPlugin
        contentEditable={<ContentEditable spellCheck={false} />}
        placeholder={<Placeholder />}
        ErrorBoundary={LexicalErrorBoundary}
      />
      <FloatingMenuPlugin
        MenuComponent={YourFloatingMenuUI}
        element={document.getElementById('editor-wrapper')}
      />
    </LexicalComposer>
  </div>

Then everything should work as expected 👍

https://github.com/konstantinmuenster/lexical-floating-menu/assets/46243719/98e9a8e0-b986-4a17-a3ae-2cc60024c308