@@ -369,8 +369,8 @@ export const BModal = /*#__PURE__*/ Vue.extend({
369
369
// Listen for `bv:modal::show events`, and close ourselves if the
370
370
// opening modal not us
371
371
this . listenOnRoot ( getRootEventName ( NAME_MODAL , EVENT_NAME_SHOW ) , this . modalListener )
372
- // Initially show modal?
373
- if ( this [ MODEL_PROP_NAME ] === true ) {
372
+ // Initially show modal
373
+ if ( this [ MODEL_PROP_NAME ] ) {
374
374
this . $nextTick ( this . show )
375
375
}
376
376
} ,
@@ -384,6 +384,41 @@ export const BModal = /*#__PURE__*/ Vue.extend({
384
384
}
385
385
} ,
386
386
methods : {
387
+ // Private method to get the current document active element
388
+ getActiveElement ( ) {
389
+ // Returning focus to `document.body` may cause unwanted scrolls,
390
+ // so we exclude setting focus on body
391
+ const activeElement = getActiveElement ( IS_BROWSER ? [ document . body ] : [ ] )
392
+ // Preset the fallback return focus value if it is not set
393
+ // `document.activeElement` should be the trigger element that was clicked or
394
+ // in the case of using the v-model, which ever element has current focus
395
+ // Will be overridden by some commands such as toggle, etc.
396
+ // Note: On IE 11, `document.activeElement` may be `null`
397
+ // So we test it for truthiness first
398
+ // https://github.com/bootstrap-vue/bootstrap-vue/issues/3206
399
+ return activeElement && activeElement . focus ? activeElement : null
400
+ } ,
401
+ buildEvent ( type , options = { } ) {
402
+ return new BvModalEvent ( type , {
403
+ // Default options
404
+ cancelable : false ,
405
+ target : this . $refs . modal || this . $el || null ,
406
+ relatedTarget : null ,
407
+ trigger : null ,
408
+ // Supplied options
409
+ ...options ,
410
+ // Options that can't be overridden
411
+ vueTarget : this ,
412
+ componentId : this . modalId
413
+ } )
414
+ } ,
415
+ emitEvent ( bvEvent ) {
416
+ const { type } = bvEvent
417
+ // We emit on `$root` first in case a global listener wants to cancel
418
+ // the event first before the instance emits its event
419
+ this . emitOnRoot ( getRootEventName ( NAME_MODAL , type ) , bvEvent , bvEvent . componentId )
420
+ this . $emit ( type , bvEvent )
421
+ } ,
387
422
setObserver ( on = false ) {
388
423
this . $_observer && this . $_observer . disconnect ( )
389
424
this . $_observer = null
@@ -395,32 +430,16 @@ export const BModal = /*#__PURE__*/ Vue.extend({
395
430
)
396
431
}
397
432
} ,
398
- // Private method to update the v-model
433
+ // Private method to update the ` v-model`
399
434
updateModel ( value ) {
400
435
if ( value !== this [ MODEL_PROP_NAME ] ) {
401
436
this . $emit ( MODEL_EVENT_NAME , value )
402
437
}
403
438
} ,
404
- // Private method to create a BvModalEvent object
405
- buildEvent ( type , options = { } ) {
406
- return new BvModalEvent ( type , {
407
- // Default options
408
- cancelable : false ,
409
- target : this . $refs . modal || this . $el || null ,
410
- relatedTarget : null ,
411
- trigger : null ,
412
- // Supplied options
413
- ...options ,
414
- // Options that can't be overridden
415
- vueTarget : this ,
416
- componentId : this . modalId
417
- } )
418
- } ,
419
- // Public method to show modal
420
439
show ( ) {
440
+ // If already open, or in the process of opening, do nothing
441
+ /* istanbul ignore next */
421
442
if ( this . isVisible || this . isOpening ) {
422
- // If already open, or in the process of opening, do nothing
423
- /* istanbul ignore next */
424
443
return
425
444
}
426
445
/* istanbul ignore next */
@@ -448,10 +467,10 @@ export const BModal = /*#__PURE__*/ Vue.extend({
448
467
// Show the modal
449
468
this . doShow ( )
450
469
} ,
451
- // Public method to hide modal
452
470
hide ( trigger = '' ) {
471
+ // If already closed, or in the process of closing, do nothing
472
+ /* istanbul ignore next */
453
473
if ( ! this . isVisible || this . isClosing ) {
454
- /* istanbul ignore next */
455
474
return
456
475
}
457
476
this . isClosing = true
@@ -482,7 +501,6 @@ export const BModal = /*#__PURE__*/ Vue.extend({
482
501
// Update the v-model
483
502
this . updateModel ( false )
484
503
} ,
485
- // Public method to toggle modal visibility
486
504
toggle ( triggerEl ) {
487
505
if ( triggerEl ) {
488
506
this . $_returnFocus = triggerEl
@@ -493,20 +511,6 @@ export const BModal = /*#__PURE__*/ Vue.extend({
493
511
this . show ( )
494
512
}
495
513
} ,
496
- // Private method to get the current document active element
497
- getActiveElement ( ) {
498
- // Returning focus to `document.body` may cause unwanted scrolls,
499
- // so we exclude setting focus on body
500
- const activeElement = getActiveElement ( IS_BROWSER ? [ document . body ] : [ ] )
501
- // Preset the fallback return focus value if it is not set
502
- // `document.activeElement` should be the trigger element that was clicked or
503
- // in the case of using the v-model, which ever element has current focus
504
- // Will be overridden by some commands such as toggle, etc.
505
- // Note: On IE 11, `document.activeElement` may be `null`
506
- // So we test it for truthiness first
507
- // https://github.com/bootstrap-vue/bootstrap-vue/issues/3206
508
- return activeElement && activeElement . focus ? activeElement : null
509
- } ,
510
514
// Private method to finish showing modal
511
515
doShow ( ) {
512
516
/* istanbul ignore next: commenting out for now until we can test stacking */
@@ -588,13 +592,6 @@ export const BModal = /*#__PURE__*/ Vue.extend({
588
592
this . emitEvent ( this . buildEvent ( EVENT_NAME_HIDDEN ) )
589
593
} )
590
594
} ,
591
- emitEvent ( bvEvent ) {
592
- const { type } = bvEvent
593
- // We emit on `$root` first in case a global listener wants to cancel
594
- // the event first before the instance emits its event
595
- this . emitOnRoot ( getRootEventName ( NAME_MODAL , type ) , bvEvent , bvEvent . componentId )
596
- this . $emit ( type , bvEvent )
597
- } ,
598
595
// UI event handlers
599
596
onDialogMousedown ( ) {
600
597
// Watch to see if the matching mouseup event occurs outside the dialog
0 commit comments