gravity-ui / markdown-editor

Markdown wysiwyg and markup editor
https://preview.gravity-ui.com/md-editor/
MIT License
158 stars 6 forks source link

Sticky behavior breaks in editor with parent overflow: auto #368

Open makhnatkin opened 3 weeks ago

makhnatkin commented 3 weeks ago

Problem Statement

When the editor is placed inside a parent container with overflow: auto, the condition at this line (refPageOffset <= stickyOffset) fails to trigger, causing the sticky header functionality to stop working as expected.

Possible Solutions

  1. Utilizing Intersection Observer API:
    We can explore using the Intersection Observer API to detect when elements enter or exit the viewport. This method would involve observing multiple elements, including those that might dynamically change. However, elements with position: sticky may not trigger the observer effectively due to their inherent visibility within the viewport.

  2. Direct Position Comparison:
    A simpler approach might involve directly comparing the initial top position of the ref component with the window scroll position or the scroll position of the nearest parent which has overflow: auto or window.

Key Considerations

makhnatkin commented 3 weeks ago

We should also check the behavior in the Popup