forked from bootstrap-vue/bootstrap-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
53 lines (51 loc) · 998 Bytes
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { matches, select, isVisible, requestAF } from '../utils/dom'
const SELECTOR = 'input, textarea, select'
// @vue/component
export default {
props: {
name: {
type: String
// default: undefined
},
id: {
type: String
// default: undefined
},
disabled: {
type: Boolean
},
required: {
type: Boolean,
default: false
},
form: {
type: String,
default: null
},
autofocus: {
type: Boolean,
default: false
}
},
mounted() {
this.handleAutofocus()
},
activated() /* istanbul ignore next */ {
this.handleAutofocus()
},
methods: {
handleAutofocus() {
this.$nextTick(() => {
requestAF(() => {
let el = this.$el
if (this.autofocus && isVisible(el)) {
if (!matches(el, SELECTOR)) {
el = select(SELECTOR, el)
}
el && el.focus && el.focus()
}
})
})
}
}
}