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
45 lines (43 loc) • 1.18 kB
JavaScript
import { extend } from '../vue'
import { EVENT_OPTIONS_NO_CAPTURE } from '../constants/events'
import { eventOn, eventOff } from '../utils/events'
// @vue/component
export const focusInMixin = extend({
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() {
eventOff(this.focusInElement, 'focusin', this._focusInHandler, EVENT_OPTIONS_NO_CAPTURE)
},
methods: {
_focusInHandler(event) {
if (this.focusInHandler) {
this.focusInHandler(event)
}
}
}
})