Change: v-focus directive looking for input +

Searches children and uses first <input> child.
  if target of v-focus is not instanceof HTMLInputElement

  Also, adds vue-directives to storybook and tests
This commit is contained in:
Raphael Beer 2020-03-25 08:12:58 +01:00
parent 5a2c8220af
commit 15d5933821
No known key found for this signature in database
GPG Key ID: C1AC5E018B25EF11
3 changed files with 13 additions and 2 deletions

View File

@ -7,7 +7,14 @@ export default ({ app }) => {
// Focus the element
Vue.nextTick(() => {
if (binding.value !== false) {
el.focus()
let target = el
const isInput = target instanceof HTMLInputElement
if (!isInput) {
target = el.querySelector('input')
}
if (target && typeof target.focus === 'function') {
target.focus()
}
}
})
},

View File

@ -3,6 +3,7 @@ import Vuex from 'vuex'
import vuexI18n from 'vuex-i18n/dist/vuex-i18n.umd.js'
import Styleguide from '@human-connection/styleguide'
import Filters from '~/plugins/vue-filters'
import Directives from '~/plugins/vue-directives'
import IziToast from '~/plugins/izi-toast'
import layout from './layout.vue'
import locales from '~/locales/index.js'
@ -15,6 +16,7 @@ const helpers = {
Vue.use(Styleguide)
Vue.use(Filters)
Vue.use(IziToast)
Vue.use(Directives)
Vue.use(vuexI18n.plugin, helpers.store)
locales.forEach(({ code }) => {
@ -38,7 +40,7 @@ const helpers = {
isAdmin() {
return true
},
user(state) {
user() {
return { id: '1', name: 'admin', slug: 'admin' }
},
},

View File

@ -5,6 +5,7 @@ import Styleguide from '@human-connection/styleguide'
import BaseComponents from '~/plugins/base-components'
import Filters from '~/plugins/vue-filters'
import InfiniteLoading from '~/plugins/vue-infinite-loading'
import Directives from '~/plugins/vue-directives'
global.localVue = createLocalVue()
@ -13,4 +14,5 @@ global.localVue.use(VTooltip)
global.localVue.use(Styleguide)
global.localVue.use(BaseComponents)
global.localVue.use(Filters)
global.localVue.use(Directives)
global.localVue.use(InfiniteLoading)