Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(b-dropdown): root events (#6198)
  • Loading branch information
jacobmllr95 committed Dec 14, 2020
1 parent 9722376 commit 6dcd233
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/components/modal/modal.js
Expand Up @@ -588,13 +588,12 @@ export const BModal = /*#__PURE__*/ Vue.extend({
this.emitEvent(this.buildEvent(EVENT_NAME_HIDDEN))
})
},
// Event emitter
emitEvent(bvModalEvt) {
const type = bvModalEvt.type
// We emit on root first incase a global listener wants to cancel
emitEvent(bvEvent) {
const { type } = bvEvent
// We emit on `$root` first in case a global listener wants to cancel
// the event first before the instance emits its event
this.emitOnRoot(getRootEventName(NAME_MODAL, type), bvModalEvt, bvModalEvt.componentId)
this.$emit(type, bvModalEvt)
this.emitOnRoot(getRootEventName(NAME_MODAL, type), bvEvent, bvEvent.componentId)
this.$emit(type, bvEvent)
},
// UI event handlers
onDialogMousedown() {
Expand Down
13 changes: 5 additions & 8 deletions src/components/tooltip/helpers/bv-tooltip.js
Expand Up @@ -63,6 +63,7 @@ import { toInteger } from '../../../utils/number'
import { keys } from '../../../utils/object'
import { warn } from '../../../utils/warn'
import { BvEvent } from '../../../utils/bv-event.class'
import { listenOnRootMixin } from '../../../mixins/listen-on-root'
import { BVTooltipTemplate } from './bv-tooltip-template'

// --- Constants ---
Expand Down Expand Up @@ -138,6 +139,7 @@ const templateData = {
// @vue/component
export const BVTooltip = /*#__PURE__*/ Vue.extend({
name: NAME_TOOLTIP_HELPER,
mixins: [listenOnRootMixin],
data() {
return {
// BTooltip/BPopover/VBTooltip/VBPopover will update this data
Expand Down Expand Up @@ -681,14 +683,9 @@ export const BVTooltip = /*#__PURE__*/ Vue.extend({
})
},
emitEvent(bvEvent) {
// Emits a BvEvent on $root and this instance
const eventName = bvEvent.type
const $root = this.$root
if ($root && $root.$emit) {
// Emit an event on $root
$root.$emit(getRootEventName(this.templateType, eventName), bvEvent)
}
this.$emit(eventName, bvEvent)
const { type } = bvEvent
this.emitOnRoot(getRootEventName(this.templateType, type), bvEvent)
this.$emit(type, bvEvent)
},
// --- Event handler setup methods ---
listen() {
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/dropdown.js
Expand Up @@ -184,8 +184,8 @@ export const dropdownMixin = Vue.extend({
// Event emitter
emitEvent(bvEvent) {
const { type } = bvEvent
this.emitOnRoot(getRootEventName(NAME_DROPDOWN, type), bvEvent)
this.$emit(type, bvEvent)
this.emitOnRoot(getRootEventName(NAME_DROPDOWN, type))
},
showMenu() {
if (this.disabled) {
Expand Down

0 comments on commit 6dcd233

Please sign in to comment.