2
2
// Based loosely on https://adamwathan.me/renderless-components-in-vuejs/
3
3
import { Vue } from '../../vue'
4
4
import { NAME_FORM_TAGS } from '../../constants/components'
5
- import { EVENT_NAME_TAG_STATE , EVENT_OPTIONS_PASSIVE } from '../../constants/events'
5
+ import {
6
+ EVENT_NAME_BLUR ,
7
+ EVENT_NAME_FOCUS ,
8
+ EVENT_NAME_FOCUSIN ,
9
+ EVENT_NAME_FOCUSOUT ,
10
+ EVENT_NAME_TAG_STATE ,
11
+ EVENT_OPTIONS_PASSIVE
12
+ } from '../../constants/events'
6
13
import { CODE_BACKSPACE , CODE_DELETE , CODE_ENTER } from '../../constants/key-codes'
7
14
import {
8
15
PROP_TYPE_ARRAY ,
@@ -24,7 +31,7 @@ import { identity } from '../../utils/identity'
24
31
import { isEvent , isNumber , isString } from '../../utils/inspect'
25
32
import { looseEqual } from '../../utils/loose-equal'
26
33
import { makeModelMixin } from '../../utils/model'
27
- import { pick , sortKeys } from '../../utils/object'
34
+ import { omit , pick , sortKeys } from '../../utils/object'
28
35
import { hasPropFunction , makeProp , makePropsConfigurable } from '../../utils/props'
29
36
import { escapeRegExp , toString , trim , trimLeft } from '../../utils/string'
30
37
import { formControlMixin , props as formControlProps } from '../../mixins/form-control'
@@ -154,7 +161,8 @@ export const BFormTags = /*#__PURE__*/ Vue.extend({
154
161
// Tags that were removed
155
162
removedTags : [ ] ,
156
163
// Populated when tags are parsed
157
- tagsState : cleanTagsState ( )
164
+ tagsState : cleanTagsState ( ) ,
165
+ focusState : null
158
166
}
159
167
} ,
160
168
computed : {
@@ -180,9 +188,11 @@ export const BFormTags = /*#__PURE__*/ Vue.extend({
180
188
} ,
181
189
computedInputHandlers ( ) {
182
190
return {
183
- ...this . bvListeners ,
184
- input : this . onInputInput ,
191
+ ...omit ( this . bvListeners , [ EVENT_NAME_FOCUSIN , EVENT_NAME_FOCUSOUT ] ) ,
192
+ blur : this . onInputBlur ,
185
193
change : this . onInputChange ,
194
+ focus : this . onInputFocus ,
195
+ input : this . onInputInput ,
186
196
keydown : this . onInputKeydown ,
187
197
reset : this . reset
188
198
}
@@ -411,11 +421,39 @@ export const BFormTags = /*#__PURE__*/ Vue.extend({
411
421
} )
412
422
}
413
423
} ,
414
- onFocusin ( ) {
424
+ onInputFocus ( event ) {
425
+ if ( this . focusState !== 'out' ) {
426
+ this . focusState = 'in'
427
+ this . $nextTick ( ( ) => {
428
+ requestAF ( ( ) => {
429
+ if ( this . hasFocus ) {
430
+ this . $emit ( EVENT_NAME_FOCUS , event )
431
+ this . focusState = null
432
+ }
433
+ } )
434
+ } )
435
+ }
436
+ } ,
437
+ onInputBlur ( event ) {
438
+ if ( this . focusState !== 'in' ) {
439
+ this . focusState = 'out'
440
+ this . $nextTick ( ( ) => {
441
+ requestAF ( ( ) => {
442
+ if ( ! this . hasFocus ) {
443
+ this . $emit ( EVENT_NAME_BLUR , event )
444
+ this . focusState = null
445
+ }
446
+ } )
447
+ } )
448
+ }
449
+ } ,
450
+ onFocusin ( event ) {
415
451
this . hasFocus = true
452
+ this . $emit ( EVENT_NAME_FOCUSIN , event )
416
453
} ,
417
- onFocusout ( ) {
454
+ onFocusout ( event ) {
418
455
this . hasFocus = false
456
+ this . $emit ( EVENT_NAME_FOCUSOUT , event )
419
457
} ,
420
458
handleAutofocus ( ) {
421
459
this . $nextTick ( ( ) => {
0 commit comments