Skip to content

Commit 28e07ec

Browse files
authored
Replace jquery in the profile selector (#2664)
1 parent f87014a commit 28e07ec

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

src/renderer/components/ft-card/ft-card.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div class="ft-card">
2+
<div
3+
class="ft-card"
4+
@focusout="$emit('focusout')"
5+
>
36
<slot />
47
</div>
58
</template>

src/renderer/components/ft-profile-selector/ft-profile-selector.css

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
text-align: center;
2020
}
2121

22-
#profileList {
23-
display: none;
22+
.profileList {
23+
display: inline;
2424
position: absolute;
2525
top: 60px;
2626
right: 10px;
@@ -31,11 +31,6 @@
3131
box-shadow: 0 0 4px var(--scrollbar-color-hover);
3232
}
3333

34-
#profileList:focus {
35-
display: inline;
36-
outline: none;
37-
}
38-
3934
.profileWrapper {
4035
margin-top: 60px;
4136
height: 340px;
@@ -71,7 +66,7 @@
7166

7267
.profileListTitle {
7368
position: absolute;
74-
top: -15px;
69+
margin: 0;
7570
left: 10px;
7671
}
7772

src/renderer/components/ft-profile-selector/ft-profile-selector.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Vue from 'vue'
22
import { mapActions } from 'vuex'
3-
import $ from 'jquery'
43

54
import FtCard from '../../components/ft-card/ft-card.vue'
65
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
@@ -13,7 +12,8 @@ export default Vue.extend({
1312
},
1413
data: function () {
1514
return {
16-
profileListShown: false
15+
profileListShown: false,
16+
mouseDownOnIcon: false
1717
}
1818
},
1919
computed: {
@@ -27,43 +27,46 @@ export default Vue.extend({
2727
return this.$store.getters.getDefaultProfile
2828
},
2929
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() : ''
3131
},
3232
profileInitials: function () {
3333
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() : ''
3535
})
3636
}
3737
},
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-
},
4838
methods: {
4939
toggleProfileList: function () {
50-
const profileList = $('#profileList')
40+
this.profileListShown = !this.profileListShown
5141

5242
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+
})
5948
}
6049
},
6150

6251
openProfileSettings: function () {
6352
this.$router.push({
6453
path: '/settings/profile/'
6554
})
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+
}
6770
},
6871

6972
setActiveProfile: function (profile) {
@@ -80,7 +83,7 @@ export default Vue.extend({
8083
}
8184
}
8285

83-
$('#profileList').trigger('focusout')
86+
this.profileListShown = false
8487
},
8588

8689
...mapActions([

src/renderer/components/ft-profile-selector/ft-profile-selector.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class="colorOption"
55
:style="{ background: activeProfile.bgColor, color: activeProfile.textColor }"
66
@click="toggleProfileList"
7+
@mousedown="handleIconMouseDown"
78
>
89
<div
910
class="initial"
@@ -12,8 +13,11 @@
1213
</div>
1314
</div>
1415
<ft-card
15-
id="profileList"
16+
v-show="profileListShown"
17+
ref="profileList"
18+
class="profileList"
1619
tabindex="-1"
20+
@focusout="handleProfileListFocusOut"
1721
>
1822
<h3
1923
class="profileListTitle"

0 commit comments

Comments
 (0)