@@ -89,35 +89,34 @@ const metadata = {
89
89
events : /** @lends sap.ui.webcomponents.main.Popup.prototype */ {
90
90
91
91
/**
92
- * Fired before the component is opened.
92
+ * Fired before the component is opened. This event can be cancelled, which will prevent the popup from opening. This event does not bubble.
93
93
*
94
94
* @public
95
95
* @event sap.ui.webcomponents.main.Popup#before-open
96
96
*/
97
-
98
97
"before-open" : { } ,
98
+
99
99
/**
100
- * Fired after the component is opened.
100
+ * Fired after the component is opened. This event does not bubble.
101
101
*
102
102
* @public
103
103
* @event sap.ui.webcomponents.main.Popup#after-open
104
104
*/
105
-
106
105
"after-open" : { } ,
106
+
107
107
/**
108
- * Fired before the component is closed.
108
+ * Fired before the component is closed. This event can be cancelled, which will prevent the popup from closing. This event does not bubble.
109
109
*
110
110
* @public
111
111
* @event sap.ui.webcomponents.main.Popup#before-close
112
112
* @param {Boolean } escPressed Indicates that <code>ESC</code> key has triggered the event.
113
113
*/
114
-
115
114
"before-close" : {
116
115
escPressed : { type : Boolean } ,
117
116
} ,
118
117
119
118
/**
120
- * Fired after the component is closed.
119
+ * Fired after the component is closed. This event does not bubble.
121
120
*
122
121
* @public
123
122
* @event sap.ui.webcomponents.main.Popup#after-close
@@ -297,6 +296,11 @@ class Popup extends UI5Element {
297
296
* @public
298
297
*/
299
298
open ( preventInitialFocus ) {
299
+ const prevented = ! this . fireEvent ( "before-open" , { } , true , false ) ;
300
+ if ( prevented ) {
301
+ return ;
302
+ }
303
+
300
304
if ( this . isModal ) {
301
305
// create static area item ref for block layer
302
306
this . getStaticAreaItemDomRef ( ) ;
@@ -306,9 +310,7 @@ class Popup extends UI5Element {
306
310
307
311
this . _zIndex = getNextZIndex ( ) ;
308
312
this . style . zIndex = this . _zIndex ;
309
-
310
313
this . _focusedElementBeforeOpen = getFocusedElement ( ) ;
311
- this . fireEvent ( "before-open" , { } ) ;
312
314
this . show ( ) ;
313
315
314
316
if ( ! this . _disableInitialFocus && ! preventInitialFocus ) {
@@ -318,7 +320,7 @@ class Popup extends UI5Element {
318
320
this . _addOpenedPopup ( ) ;
319
321
320
322
this . opened = true ;
321
- this . fireEvent ( "after-open" , { } ) ;
323
+ this . fireEvent ( "after-open" , { } , false , false ) ;
322
324
}
323
325
324
326
/**
@@ -334,8 +336,12 @@ class Popup extends UI5Element {
334
336
* @public
335
337
*/
336
338
close ( escPressed = false , preventRegistryUpdate = false , preventFocusRestore = false ) {
337
- const prevented = ! this . fireEvent ( "before-close" , { escPressed } , true ) ;
338
- if ( prevented || ! this . opened ) {
339
+ if ( ! this . opened ) {
340
+ return ;
341
+ }
342
+
343
+ const prevented = ! this . fireEvent ( "before-close" , { escPressed } , true , false ) ;
344
+ if ( prevented ) {
339
345
return ;
340
346
}
341
347
@@ -355,7 +361,7 @@ class Popup extends UI5Element {
355
361
this . resetFocus ( ) ;
356
362
}
357
363
358
- this . fireEvent ( "after-close" , { } ) ;
364
+ this . fireEvent ( "after-close" , { } , false , false ) ;
359
365
}
360
366
361
367
/**
0 commit comments