1
1
import Vue from 'vue'
2
2
import { mapActions } from 'vuex'
3
- import $ from 'jquery'
4
3
5
4
import FtCard from '../../components/ft-card/ft-card.vue'
6
5
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
@@ -13,7 +12,8 @@ export default Vue.extend({
13
12
} ,
14
13
data : function ( ) {
15
14
return {
16
- profileListShown : false
15
+ profileListShown : false ,
16
+ mouseDownOnIcon : false
17
17
}
18
18
} ,
19
19
computed : {
@@ -27,43 +27,46 @@ export default Vue.extend({
27
27
return this . $store . getters . getDefaultProfile
28
28
} ,
29
29
activeProfileInitial : function ( ) {
30
- return this ? .activeProfile ?. name ?. length > 0 ? Array . from ( this . activeProfile . name ) [ 0 ] . toUpperCase ( ) : ''
30
+ return this . activeProfile ?. name ?. length > 0 ? this . activeProfile . name [ 0 ] . toUpperCase ( ) : ''
31
31
} ,
32
32
profileInitials : function ( ) {
33
33
return this . profileList . map ( ( profile ) => {
34
- return profile ?. name ?. length > 0 ? Array . from ( profile . name ) [ 0 ] . toUpperCase ( ) : ''
34
+ return profile ?. name ?. length > 0 ? profile . name [ 0 ] . toUpperCase ( ) : ''
35
35
} )
36
36
}
37
37
} ,
38
- mounted : function ( ) {
39
- $ ( '#profileList' ) . focusout ( ( ) => {
40
- $ ( '#profileList' ) [ 0 ] . style . display = 'none'
41
- // When pressing the profile button
42
- // It will make the menu reappear if we set `profileListShown` immediately
43
- setTimeout ( ( ) => {
44
- this . profileListShown = false
45
- } , 100 )
46
- } )
47
- } ,
48
38
methods : {
49
39
toggleProfileList : function ( ) {
50
- const profileList = $ ( '#profileList' )
40
+ this . profileListShown = ! this . profileListShown
51
41
52
42
if ( this . profileListShown ) {
53
- profileList . get ( 0 ) . style . display = 'none'
54
- this . profileListShown = false
55
- } else {
56
- profileList . get ( 0 ) . style . display = 'inline'
57
- profileList . get ( 0 ) . focus ( )
58
- this . profileListShown = true
43
+ // wait until the profile list is visible
44
+ // then focus it so we can hide it automatically when it loses focus
45
+ setTimeout ( ( ) => {
46
+ this . $refs . profileList . $el . focus ( )
47
+ } )
59
48
}
60
49
} ,
61
50
62
51
openProfileSettings : function ( ) {
63
52
this . $router . push ( {
64
53
path : '/settings/profile/'
65
54
} )
66
- $ ( '#profileList' ) . focusout ( )
55
+ this . profileListShown = false
56
+ } ,
57
+
58
+ handleIconMouseDown : function ( ) {
59
+ if ( this . profileListShown ) {
60
+ this . mouseDownOnIcon = true
61
+ }
62
+ } ,
63
+
64
+ handleProfileListFocusOut : function ( ) {
65
+ if ( this . mouseDownOnIcon ) {
66
+ this . mouseDownOnIcon = false
67
+ } else if ( ! this . $refs . profileList . $el . matches ( ':focus-within' ) ) {
68
+ this . profileListShown = false
69
+ }
67
70
} ,
68
71
69
72
setActiveProfile : function ( profile ) {
@@ -80,7 +83,7 @@ export default Vue.extend({
80
83
}
81
84
}
82
85
83
- $ ( '#profileList' ) . trigger ( 'focusout' )
86
+ this . profileListShown = false
84
87
} ,
85
88
86
89
...mapActions ( [
0 commit comments