# All files / src/menu utils.ts

100% Statements 62/62
100% Branches 17/17
100% Functions 1/1
100% Lines 62/62

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    631x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    418x
    418x
    418x
    418x
    1x
    1x
    417x
    417x
    418x
    1x
    418x
    2x
    418x
    1x
    418x
    1x
    418x
    412x
    418x
    234x
    234x
    178x
    188x
    1x
    1x
    177x
    177x
    26x
    26x
    151x
    151x
    151x
     import type { FloatingActionButtonPosition } from "../button/FloatingActionButton.js";
    import {
      BELOW_CENTER_ANCHOR,
      BELOW_INNER_LEFT_ANCHOR,
      BOTTOM_INNER_LEFT_ANCHOR,
      BOTTOM_INNER_RIGHT_ANCHOR,
      CENTER_RIGHT_ANCHOR,
      TOP_INNER_LEFT_ANCHOR,
      TOP_INNER_RIGHT_ANCHOR,
      TOP_RIGHT_ANCHOR,
    } from "../positioning/constants.js";
    import type { PositionAnchor } from "../positioning/types.js";

    /**
     * @remarks \@since 5.0.0
     * @internal
     */
    interface DefaultAnchorOptions {
      anchor?: PositionAnchor;
      menubar: boolean;
      menuitem: boolean;
      floating?: FloatingActionButtonPosition;
      horizontal: boolean;
    }

    /**
     * @remarks \@since 5.0.0
     * @internal
     */
    export const getDefaultAnchor = (
      options: DefaultAnchorOptions
    ): PositionAnchor => {
      const { anchor, menubar, menuitem, floating, horizontal } = options;
      if (anchor) {
        return anchor;
      }

      switch (floating) {
        case "bottom-left":
          return BOTTOM_INNER_LEFT_ANCHOR;
        case "bottom-right":
          return BOTTOM_INNER_RIGHT_ANCHOR;
        case "top-left":
          return TOP_INNER_LEFT_ANCHOR;
        case "top-right":
          return TOP_INNER_RIGHT_ANCHOR;
      }

      if (menubar) {
        return menuitem ? CENTER_RIGHT_ANCHOR : BELOW_INNER_LEFT_ANCHOR;
      }

      if (horizontal) {
        return BELOW_CENTER_ANCHOR;
      }

      if (menuitem) {
        return TOP_RIGHT_ANCHOR;
      }

      return TOP_INNER_RIGHT_ANCHOR;
    };