MCPcopy
hub / github.com/ionic-team/ionic-framework / get

Function get

core/src/utils/menu-controller/index.ts:85–133  ·  view source on GitHub ↗
(
    menu?: string | null,
    logOnMultipleSideMenus: boolean = false
  )

Source from the content-addressed store, hash-verified

83 * functions can choose whether or not it is appropriate to log this warning.
84 */
85 const get = async (
86 menu?: string | null,
87 logOnMultipleSideMenus: boolean = false
88 ): Promise<HTMLIonMenuElement | undefined> => {
89 await waitUntilReady();
90
91 if (menu === 'start' || menu === 'end') {
92 // there could be more than one menu on the same side
93 // so first try to get the enabled one
94 const menuRefs = menus.filter((m) => m.side === menu && !m.disabled);
95 if (menuRefs.length >= 1) {
96 if (menuRefs.length > 1 && logOnMultipleSideMenus) {
97 printIonWarning(
98 `menuController queried for a menu on the "${menu}" side, but ${menuRefs.length} menus were found. The first menu reference will be used. If this is not the behavior you want then pass the ID of the menu instead of its side.`,
99 menuRefs.map((m) => m.el)
100 );
101 }
102
103 return menuRefs[0].el;
104 }
105
106 // didn't find a menu side that is enabled
107 // so try to get the first menu side found
108 const sideMenuRefs = menus.filter((m) => m.side === menu);
109 if (sideMenuRefs.length >= 1) {
110 if (sideMenuRefs.length > 1 && logOnMultipleSideMenus) {
111 printIonWarning(
112 `menuController queried for a menu on the "${menu}" side, but ${sideMenuRefs.length} menus were found. The first menu reference will be used. If this is not the behavior you want then pass the ID of the menu instead of its side.`,
113 sideMenuRefs.map((m) => m.el)
114 );
115 }
116
117 return sideMenuRefs[0].el;
118 }
119 } else if (menu != null) {
120 // the menuId was not left or right
121 // so try to get the menu by its "id"
122 return find((m) => m.menuId === menu);
123 }
124
125 // return the first enabled menu
126 const menuEl = find((m) => !m.disabled);
127 if (menuEl) {
128 return menuEl;
129 }
130
131 // get the first menu in the array, if one exists
132 return menus.length > 0 ? menus[0].el : undefined;
133 };
134
135 /**
136 * Get the instance of the opened menu. Returns `null` if a menu is not found.

Callers 7

openFunction · 0.70
closeFunction · 0.70
toggleFunction · 0.70
enableFunction · 0.70
swipeGestureFunction · 0.70
isOpenFunction · 0.70
isEnabledFunction · 0.70

Calls 3

printIonWarningFunction · 0.90
waitUntilReadyFunction · 0.85
findFunction · 0.85

Tested by

no test coverage detected