@@ -137,36 +137,54 @@ export class MenuController {
137
137
* Progamatically open the Menu.
138
138
* @return {Promise } returns a promise when the menu is fully opened
139
139
*/
140
- open ( menuId ?: string ) {
140
+ open ( menuId ?: string ) : Promise < boolean > {
141
141
let menu = this . get ( menuId ) ;
142
142
if ( menu ) {
143
143
return menu . open ( ) ;
144
144
}
145
+
146
+ return Promise . resolve ( false ) ;
145
147
}
146
148
147
149
/**
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.
149
153
* @param {string } [menuId] Optionally get the menu by its id, or side.
150
154
* @return {Promise } returns a promise when the menu is fully closed
151
155
*/
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
+
154
168
if ( menu ) {
169
+ // close the menu
155
170
return menu . close ( ) ;
156
171
}
172
+
173
+ return Promise . resolve ( false ) ;
157
174
}
158
175
159
176
/**
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.
162
179
* @param {string } [menuId] Optionally get the menu by its id, or side.
163
180
* @return {Promise } returns a promise when the menu has been toggled
164
181
*/
165
- toggle ( menuId ?: string ) {
182
+ toggle ( menuId ?: string ) : Promise < boolean > {
166
183
let menu = this . get ( menuId ) ;
167
184
if ( menu ) {
168
185
return menu . toggle ( ) ;
169
186
}
187
+ return Promise . resolve ( false ) ;
170
188
}
171
189
172
190
/**
@@ -176,7 +194,7 @@ export class MenuController {
176
194
* @param {string } [menuId] Optionally get the menu by its id, or side.
177
195
* @return {Menu } Returns the instance of the menu, which is useful for chaining.
178
196
*/
179
- enable ( shouldEnable : boolean , menuId ?: string ) {
197
+ enable ( shouldEnable : boolean , menuId ?: string ) : Menu {
180
198
let menu = this . get ( menuId ) ;
181
199
if ( menu ) {
182
200
return menu . enable ( shouldEnable ) ;
@@ -189,7 +207,7 @@ export class MenuController {
189
207
* @param {string } [menuId] Optionally get the menu by its id, or side.
190
208
* @return {Menu } Returns the instance of the menu, which is useful for chaining.
191
209
*/
192
- swipeEnable ( shouldEnable : boolean , menuId ?: string ) {
210
+ swipeEnable ( shouldEnable : boolean , menuId ?: string ) : Menu {
193
211
let menu = this . get ( menuId ) ;
194
212
if ( menu ) {
195
213
return menu . swipeEnable ( shouldEnable ) ;
0 commit comments