@@ -137,36 +137,54 @@ export class MenuController {
137137 * Progamatically open the Menu.
138138 * @return {Promise } returns a promise when the menu is fully opened
139139 */
140- open ( menuId ?: string ) {
140+ open ( menuId ?: string ) : Promise < boolean > {
141141 let menu = this . get ( menuId ) ;
142142 if ( menu ) {
143143 return menu . open ( ) ;
144144 }
145+
146+ return Promise . resolve ( false ) ;
145147 }
146148
147149 /**
148- * Progamatically close the Menu.
150+ * Progamatically close the Menu. If no `menuId` is given as the first
151+ * argument then it'll close any menu which is open. If a `menuId`
152+ * is given then it'll close that exact menu.
149153 * @param {string } [menuId] Optionally get the menu by its id, or side.
150154 * @return {Promise } returns a promise when the menu is fully closed
151155 */
152- close ( menuId ?: string ) {
153- let menu = this . get ( menuId ) ;
156+ close ( menuId ?: string ) : Promise < boolean > {
157+ let menu : Menu ;
158+
159+ if ( menuId ) {
160+ // find the menu by its id
161+ menu = this . get ( menuId ) ;
162+
163+ } else {
164+ // find the menu that is open
165+ menu = this . _menus . find ( m => m . isOpen ) ;
166+ }
167+
154168 if ( menu ) {
169+ // close the menu
155170 return menu . close ( ) ;
156171 }
172+
173+ return Promise . resolve ( false ) ;
157174 }
158175
159176 /**
160- * Toggle the menu. If it's closed, it will open, and if opened, it will
161- * close.
177+ * Toggle the menu. If it's closed, it will open, and if opened, it
178+ * will close.
162179 * @param {string } [menuId] Optionally get the menu by its id, or side.
163180 * @return {Promise } returns a promise when the menu has been toggled
164181 */
165- toggle ( menuId ?: string ) {
182+ toggle ( menuId ?: string ) : Promise < boolean > {
166183 let menu = this . get ( menuId ) ;
167184 if ( menu ) {
168185 return menu . toggle ( ) ;
169186 }
187+ return Promise . resolve ( false ) ;
170188 }
171189
172190 /**
@@ -176,7 +194,7 @@ export class MenuController {
176194 * @param {string } [menuId] Optionally get the menu by its id, or side.
177195 * @return {Menu } Returns the instance of the menu, which is useful for chaining.
178196 */
179- enable ( shouldEnable : boolean , menuId ?: string ) {
197+ enable ( shouldEnable : boolean , menuId ?: string ) : Menu {
180198 let menu = this . get ( menuId ) ;
181199 if ( menu ) {
182200 return menu . enable ( shouldEnable ) ;
@@ -189,7 +207,7 @@ export class MenuController {
189207 * @param {string } [menuId] Optionally get the menu by its id, or side.
190208 * @return {Menu } Returns the instance of the menu, which is useful for chaining.
191209 */
192- swipeEnable ( shouldEnable : boolean , menuId ?: string ) {
210+ swipeEnable ( shouldEnable : boolean , menuId ?: string ) : Menu {
193211 let menu = this . get ( menuId ) ;
194212 if ( menu ) {
195213 return menu . swipeEnable ( shouldEnable ) ;
0 commit comments