Vizel API / core/src / shouldFlipSubmenu
Function: shouldFlipSubmenu()
ts
function shouldFlipSubmenu(
parentRect,
submenuWidth,
gap?,
padding?): boolean;Defined in: packages/core/src/utils/menuPositioning.ts:26
Determines whether a submenu should open to the left instead of the right.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
parentRect | DOMRect | undefined | Bounding rect of the parent menu element |
submenuWidth | number | undefined | offsetWidth of the submenu (estimate 200 if unknown) |
gap | number | 4 | Horizontal gap between parent and submenu (default 4) |
padding | number | 8 | Minimum distance from viewport edge (default 8) |
Returns
boolean
true if submenu should flip to the left side
Example
ts
const parentRect = parentMenu.getBoundingClientRect();
const flip = shouldFlipSubmenu(parentRect, 200);
submenu.classList.toggle("vizel-block-menu-submenu--left", flip);