MCPcopy Index your code
hub / github.com/JedWatson/react-select / MenuPortal

Function MenuPortal

packages/react-select/src/components/Menu.tsx:590–705  ·  view source on GitHub ↗
(
  props: MenuPortalProps<Option, IsMulti, Group>
)

Source from the content-addressed store, hash-verified

588}
589
590export const MenuPortal = <
591 Option,
592 IsMulti extends boolean,
593 Group extends GroupBase<Option>
594>(
595 props: MenuPortalProps<Option, IsMulti, Group>
596) => {
597 const {
598 appendTo,
599 children,
600 controlElement,
601 innerProps,
602 menuPlacement,
603 menuPosition,
604 } = props;
605
606 const menuPortalRef = useRef<HTMLDivElement | null>(null);
607 const cleanupRef = useRef<(() => void) | void | null>(null);
608
609 const [placement, setPortalPlacement] = useState<'bottom' | 'top'>(
610 coercePlacement(menuPlacement)
611 );
612 const portalPlacementContext = useMemo(
613 () => ({
614 setPortalPlacement,
615 }),
616 []
617 );
618 const [computedPosition, setComputedPosition] =
619 useState<ComputedPosition | null>(null);
620
621 const updateComputedPosition = useCallback(() => {
622 if (!controlElement) return;
623
624 const rect = getBoundingClientObj(controlElement);
625 const scrollDistance = menuPosition === 'fixed' ? 0 : window.pageYOffset;
626 const offset = rect[placement] + scrollDistance;
627 if (
628 offset !== computedPosition?.offset ||
629 rect.left !== computedPosition?.rect.left ||
630 rect.width !== computedPosition?.rect.width
631 ) {
632 setComputedPosition({ offset, rect });
633 }
634 }, [
635 controlElement,
636 menuPosition,
637 placement,
638 computedPosition?.offset,
639 computedPosition?.rect.left,
640 computedPosition?.rect.width,
641 ]);
642
643 useLayoutEffect(() => {
644 updateComputedPosition();
645 }, [updateComputedPosition]);
646
647 const runAutoUpdate = useCallback(() => {

Callers

nothing calls this directly

Calls 3

getBoundingClientObjFunction · 0.90
getStylePropsFunction · 0.90
coercePlacementFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…