bootstrap-vue
Version:
With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens
44 lines (42 loc) • 1.15 kB
JavaScript
import { EVENT_OPTIONS_NO_CAPTURE } from '../constants/events'
import { eventOn, eventOff } from '../utils/events'
// @vue/component
export default {
data() {
return {
listenForFocusIn: false
}
},
watch: {
listenForFocusIn(newValue, oldValue) {
if (newValue !== oldValue) {
eventOff(this.focusInElement, 'focusin', this._focusInHandler, EVENT_OPTIONS_NO_CAPTURE)
if (newValue) {
eventOn(this.focusInElement, 'focusin', this._focusInHandler, EVENT_OPTIONS_NO_CAPTURE)
}
}
}
},
beforeCreate() {
// Declare non-reactive properties
this.focusInElement = null
},
mounted() {
if (!this.focusInElement) {
this.focusInElement = document
}
if (this.listenForFocusIn) {
eventOn(this.focusInElement, 'focusin', this._focusInHandler, EVENT_OPTIONS_NO_CAPTURE)
}
},
beforeDestroy() /* istanbul ignore next */ {
eventOff(this.focusInElement, 'focusin', this._focusInHandler, EVENT_OPTIONS_NO_CAPTURE)
},
methods: {
_focusInHandler(evt) {
if (this.focusInHandler) {
this.focusInHandler(evt)
}
}
}
}