Skip to content

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

ParameterTypeDefault valueDescription
parentRectDOMRectundefinedBounding rect of the parent menu element
submenuWidthnumberundefinedoffsetWidth of the submenu (estimate 200 if unknown)
gapnumber4Horizontal gap between parent and submenu (default 4)
paddingnumber8Minimum 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);

Released under the MIT License.