@@ -369,8 +369,8 @@ export const BModal = /*#__PURE__*/ Vue.extend({
369369 // Listen for `bv:modal::show events`, and close ourselves if the
370370 // opening modal not us
371371 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 ] ) {
374374 this . $nextTick ( this . show )
375375 }
376376 } ,
@@ -384,6 +384,41 @@ export const BModal = /*#__PURE__*/ Vue.extend({
384384 }
385385 } ,
386386 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+ } ,
387422 setObserver ( on = false ) {
388423 this . $_observer && this . $_observer . disconnect ( )
389424 this . $_observer = null
@@ -395,32 +430,16 @@ export const BModal = /*#__PURE__*/ Vue.extend({
395430 )
396431 }
397432 } ,
398- // Private method to update the v-model
433+ // Private method to update the ` v-model`
399434 updateModel ( value ) {
400435 if ( value !== this [ MODEL_PROP_NAME ] ) {
401436 this . $emit ( MODEL_EVENT_NAME , value )
402437 }
403438 } ,
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
420439 show ( ) {
440+ // If already open, or in the process of opening, do nothing
441+ /* istanbul ignore next */
421442 if ( this . isVisible || this . isOpening ) {
422- // If already open, or in the process of opening, do nothing
423- /* istanbul ignore next */
424443 return
425444 }
426445 /* istanbul ignore next */
@@ -448,10 +467,10 @@ export const BModal = /*#__PURE__*/ Vue.extend({
448467 // Show the modal
449468 this . doShow ( )
450469 } ,
451- // Public method to hide modal
452470 hide ( trigger = '' ) {
471+ // If already closed, or in the process of closing, do nothing
472+ /* istanbul ignore next */
453473 if ( ! this . isVisible || this . isClosing ) {
454- /* istanbul ignore next */
455474 return
456475 }
457476 this . isClosing = true
@@ -482,7 +501,6 @@ export const BModal = /*#__PURE__*/ Vue.extend({
482501 // Update the v-model
483502 this . updateModel ( false )
484503 } ,
485- // Public method to toggle modal visibility
486504 toggle ( triggerEl ) {
487505 if ( triggerEl ) {
488506 this . $_returnFocus = triggerEl
@@ -493,20 +511,6 @@ export const BModal = /*#__PURE__*/ Vue.extend({
493511 this . show ( )
494512 }
495513 } ,
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- } ,
510514 // Private method to finish showing modal
511515 doShow ( ) {
512516 /* istanbul ignore next: commenting out for now until we can test stacking */
@@ -588,13 +592,6 @@ export const BModal = /*#__PURE__*/ Vue.extend({
588592 this . emitEvent ( this . buildEvent ( EVENT_NAME_HIDDEN ) )
589593 } )
590594 } ,
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- } ,
598595 // UI event handlers
599596 onDialogMousedown ( ) {
600597 // Watch to see if the matching mouseup event occurs outside the dialog
0 commit comments