fix(super-editor): flip tooltip when clipped by viewport
Closed
DA
3mo ago+1384+1384+0123456789012345678901234567890123456789-46-46-01234567890123456789
Fixes https://github.com/superdoc-dev/superdoc/issues/3786
Tooltip positioning wasn't detecting viewport collisions, it only clamped horizontally, so tooltips could still overflow on top.
This PR fixes the issue, while also refactoring some other components using the same duplicated logic. Also created a repro test for the bug.
| Before | After |
|---|---|
Refactor notes:
- Extracted the positioning logic into a standalone util function to reduce component complexity and avoid duplicated code.
- SdTooltip, FontFamilyCombobox and ToolbarDropdown, all share the new utility for positioning
- Expanded the utility to support additional alignments (bottom-start, bottom-end, etc.) to match
FontFamilyCombobox'salignment behavior - Added support for calculating available space to fit dropdown height, needed by
ToolbarDropdown - Added support for boundary elements in contrast to just using the viewport as the boundary. Could be useful for components like ContextMenu that depend on the editor container and not the viewport. Not implemented here though, since ContextMenu uses a specific plugin for this type of logic.
- Added unit tests for the new utility functions
Demo of how FontFamilyCombobox and ToolbarDropdown components behave after the change. They retain the same behavior as before. ๐