Allow drop downs to hide when clicked away

This commit is contained in:
Preston 2020-09-20 19:15:59 -04:00
parent b7013be907
commit cd7af11e89
4 changed files with 40 additions and 12 deletions

View File

@ -1,4 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import $ from 'jquery'
export default Vue.extend({ export default Vue.extend({
name: 'FtIconButton', name: 'FtIconButton',
@ -50,12 +51,34 @@ export default Vue.extend({
}, },
data: function () { data: function () {
return { return {
showDropdown: false showDropdown: false,
id: ''
} }
}, },
mounted: function () {
this.id = `iconButton${this._uid}`
},
methods: { methods: {
toggleDropdown: function () { toggleDropdown: function () {
this.showDropdown = !this.showDropdown $(`#${this.id}`)[0].style.display = 'inline'
$(`#${this.id}`).focus()
$(`#${this.id}`).focusout(() => {
const shareLinks = $(`#${this.id}`).find('.shareLinks')
if (shareLinks.length > 0) {
if (!shareLinks[0].parentNode.matches(':hover')) {
$(`#${this.id}`)[0].style.display = 'none'
}
} else {
$(`#${this.id}`)[0].style.display = 'none'
}
})
},
focusOut: function () {
$(`#${this.id}`).focusout()
$(`#${this.id}`)[0].style.display = 'none'
}, },
handleIconClick: function () { handleIconClick: function () {
@ -67,8 +90,8 @@ export default Vue.extend({
}, },
handleDropdownClick: function (index) { handleDropdownClick: function (index) {
this.toggleDropdown()
this.$emit('click', this.dropdownValues[index]) this.$emit('click', this.dropdownValues[index])
this.focusOut()
} }
} }
}) })

View File

@ -46,6 +46,7 @@
background-color: var(--accent-color-active) background-color: var(--accent-color-active)
.iconDropdown .iconDropdown
display: none
position: absolute position: absolute
text-align: center text-align: center
list-style-type: none list-style-type: none
@ -57,6 +58,9 @@
color: var(--secondary-text-color) color: var(--secondary-text-color)
user-select: none user-select: none
&:focus
display: inline
&.left &.left
right: calc(50% - 10px) right: calc(50% - 10px)

View File

@ -17,7 +17,8 @@
@click="handleIconClick" @click="handleIconClick"
/> />
<div <div
v-if="showDropdown" tabindex="-1"
:id="id"
class="iconDropdown" class="iconDropdown"
:class="{ :class="{
left: dropdownPositionX === 'left', left: dropdownPositionX === 'left',

View File

@ -68,7 +68,7 @@ export default Vue.extend({
openInvidious() { openInvidious() {
this.open(this.getFinalUrl(this.invidiousURL)) this.open(this.getFinalUrl(this.invidiousURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
copyInvidious() { copyInvidious() {
@ -76,12 +76,12 @@ export default Vue.extend({
message: this.$t('Share.Invidious URL copied to clipboard') message: this.$t('Share.Invidious URL copied to clipboard')
}) })
this.copy(this.getFinalUrl(this.invidiousURL)) this.copy(this.getFinalUrl(this.invidiousURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
openYoutube() { openYoutube() {
this.open(this.getFinalUrl(this.youtubeURL)) this.open(this.getFinalUrl(this.youtubeURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
copyYoutube() { copyYoutube() {
@ -89,12 +89,12 @@ export default Vue.extend({
message: this.$t('Share.YouTube URL copied to clipboard') message: this.$t('Share.YouTube URL copied to clipboard')
}) })
this.copy(this.getFinalUrl(this.youtubeURL)) this.copy(this.getFinalUrl(this.youtubeURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
openYoutubeEmbed() { openYoutubeEmbed() {
this.open(this.getFinalUrl(this.youtubeEmbedURL)) this.open(this.getFinalUrl(this.youtubeEmbedURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
copyYoutubeEmbed() { copyYoutubeEmbed() {
@ -102,12 +102,12 @@ export default Vue.extend({
message: this.$t('Share.YouTube Embed URL copied to clipboard') message: this.$t('Share.YouTube Embed URL copied to clipboard')
}) })
this.copy(this.getFinalUrl(this.youtubeEmbedURL)) this.copy(this.getFinalUrl(this.youtubeEmbedURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
openInvidiousEmbed() { openInvidiousEmbed() {
this.open(this.getFinalUrl(this.invidiousEmbedURL)) this.open(this.getFinalUrl(this.invidiousEmbedURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
copyInvidiousEmbed() { copyInvidiousEmbed() {
@ -115,7 +115,7 @@ export default Vue.extend({
message: this.$t('Share.Invidious Embed URL copied to clipboard') message: this.$t('Share.Invidious Embed URL copied to clipboard')
}) })
this.copy(this.getFinalUrl(this.invidiousEmbedURL)) this.copy(this.getFinalUrl(this.invidiousEmbedURL))
this.$refs.iconButton.toggleDropdown() this.$refs.iconButton.focusOut()
}, },
updateincludeTimestamp() { updateincludeTimestamp() {