fix(super-editor): flip tooltip when clipped by viewport

Closed
DA
3mo ago
+1384-46

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.

BeforeAfter
Screenshot 2026-07-18 at 01 31 32Screenshot 2026-07-18 at 01 32 48

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's alignment 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. ๐Ÿ‘‡

output