Replace jquery in the profile selector (#2664)

This commit is contained in:
absidue 2022-10-04 19:55:55 +02:00 committed by GitHub
parent f87014aedc
commit 28e07ec0aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 33 deletions

View File

@ -1,5 +1,8 @@
<template> <template>
<div class="ft-card"> <div
class="ft-card"
@focusout="$emit('focusout')"
>
<slot /> <slot />
</div> </div>
</template> </template>

View File

@ -19,8 +19,8 @@
text-align: center; text-align: center;
} }
#profileList { .profileList {
display: none; display: inline;
position: absolute; position: absolute;
top: 60px; top: 60px;
right: 10px; right: 10px;
@ -31,11 +31,6 @@
box-shadow: 0 0 4px var(--scrollbar-color-hover); box-shadow: 0 0 4px var(--scrollbar-color-hover);
} }
#profileList:focus {
display: inline;
outline: none;
}
.profileWrapper { .profileWrapper {
margin-top: 60px; margin-top: 60px;
height: 340px; height: 340px;
@ -71,7 +66,7 @@
.profileListTitle { .profileListTitle {
position: absolute; position: absolute;
top: -15px; margin: 0;
left: 10px; left: 10px;
} }

View File

@ -1,6 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import $ from 'jquery'
import FtCard from '../../components/ft-card/ft-card.vue' import FtCard from '../../components/ft-card/ft-card.vue'
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue' import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
@ -13,7 +12,8 @@ export default Vue.extend({
}, },
data: function () { data: function () {
return { return {
profileListShown: false profileListShown: false,
mouseDownOnIcon: false
} }
}, },
computed: { computed: {
@ -27,35 +27,24 @@ export default Vue.extend({
return this.$store.getters.getDefaultProfile return this.$store.getters.getDefaultProfile
}, },
activeProfileInitial: function () { activeProfileInitial: function () {
return this?.activeProfile?.name?.length > 0 ? Array.from(this.activeProfile.name)[0].toUpperCase() : '' return this.activeProfile?.name?.length > 0 ? this.activeProfile.name[0].toUpperCase() : ''
}, },
profileInitials: function () { profileInitials: function () {
return this.profileList.map((profile) => { return this.profileList.map((profile) => {
return profile?.name?.length > 0 ? Array.from(profile.name)[0].toUpperCase() : '' return profile?.name?.length > 0 ? profile.name[0].toUpperCase() : ''
}) })
} }
}, },
mounted: function () {
$('#profileList').focusout(() => {
$('#profileList')[0].style.display = 'none'
// When pressing the profile button
// It will make the menu reappear if we set `profileListShown` immediately
setTimeout(() => {
this.profileListShown = false
}, 100)
})
},
methods: { methods: {
toggleProfileList: function () { toggleProfileList: function () {
const profileList = $('#profileList') this.profileListShown = !this.profileListShown
if (this.profileListShown) { if (this.profileListShown) {
profileList.get(0).style.display = 'none' // wait until the profile list is visible
this.profileListShown = false // then focus it so we can hide it automatically when it loses focus
} else { setTimeout(() => {
profileList.get(0).style.display = 'inline' this.$refs.profileList.$el.focus()
profileList.get(0).focus() })
this.profileListShown = true
} }
}, },
@ -63,7 +52,21 @@ export default Vue.extend({
this.$router.push({ this.$router.push({
path: '/settings/profile/' path: '/settings/profile/'
}) })
$('#profileList').focusout() this.profileListShown = false
},
handleIconMouseDown: function () {
if (this.profileListShown) {
this.mouseDownOnIcon = true
}
},
handleProfileListFocusOut: function () {
if (this.mouseDownOnIcon) {
this.mouseDownOnIcon = false
} else if (!this.$refs.profileList.$el.matches(':focus-within')) {
this.profileListShown = false
}
}, },
setActiveProfile: function (profile) { setActiveProfile: function (profile) {
@ -80,7 +83,7 @@ export default Vue.extend({
} }
} }
$('#profileList').trigger('focusout') this.profileListShown = false
}, },
...mapActions([ ...mapActions([

View File

@ -4,6 +4,7 @@
class="colorOption" class="colorOption"
:style="{ background: activeProfile.bgColor, color: activeProfile.textColor }" :style="{ background: activeProfile.bgColor, color: activeProfile.textColor }"
@click="toggleProfileList" @click="toggleProfileList"
@mousedown="handleIconMouseDown"
> >
<div <div
class="initial" class="initial"
@ -12,8 +13,11 @@
</div> </div>
</div> </div>
<ft-card <ft-card
id="profileList" v-show="profileListShown"
ref="profileList"
class="profileList"
tabindex="-1" tabindex="-1"
@focusout="handleProfileListFocusOut"
> >
<h3 <h3
class="profileListTitle" class="profileListTitle"