Websites v4 docs v12.7.0
    Preparing search index...

    Function useDynamicMenuItems

    • Hook that dynamically updates how many menu items are visible in a navbar based on the container width and the collective width of the menu items in the DOM plus the size of the gap between them.

      Items are measured once they are visible (a hidden nav measures as zero width) and the fit is rechecked whenever the container resizes, so it also works when the nav becomes visible later, such as after a resize or inside an admin preview.

      Parameters

      • __namedParameters: {
            debounceInterval?: number;
            gapWidth: number;
            menuItems: MenuItem[];
            moreButtonWidth: number;
        }

      Returns UseDynamicMenuItems

      const {
      visibleItems,
      overflowItems,
      containerRef,
      menuItemRefs
      } = useDynamicMenuItems({ menuItems, gapWidth: 20, moreButtonWidth: 72 });

      ...

      return (
      <div ref={containerRef}>
      {visibleItems.map((item, index) => (
      <div ref={(el) => {
      menuItemRefs.current[index] = el;
      }}
      >
      {item.name}
      </div>
      ))}
      </div>
      )