Merge branch 'disjointed-popovers' into shigusegubu-vue3

* disjointed-popovers:
  fix errors in console
  pinned no longer needed
  popover stack
This commit is contained in:
Henry Jameson 2022-07-31 01:48:40 +03:00
commit 8d42b18de5
2 changed files with 22 additions and 31 deletions

View file

@ -53,12 +53,13 @@ const Popover = {
// with popovers refusing to be hidden when user wants to interact with something in below popover
lockReEntry: false,
hidden: true,
pinned: false,
styles: {},
oldSize: { width: 0, height: 0 },
scrollable: null,
// used to avoid blinking if hovered onto popover
graceTimeout: null
graceTimeout: null,
parentPopover: null,
childrenShown: new Set()
}
},
methods: {
@ -200,9 +201,9 @@ const Popover = {
},
showPopover () {
if (this.disabled) return
this.pinned = false
const wasHidden = this.hidden
this.hidden = false
this.parentPopover && this.parentPopover.onChildPopoverState(this, true)
if (this.trigger === 'click' || this.stayOnClick) {
document.addEventListener('click', this.onClickOutside)
}
@ -217,6 +218,7 @@ const Popover = {
if (this.disabled) return
if (!this.hidden) this.$emit('close')
this.hidden = true
this.parentPopover && this.parentPopover.onChildPopoverState(this, false)
if (this.trigger === 'click') {
document.removeEventListener('click', this.onClickOutside)
}
@ -232,7 +234,7 @@ const Popover = {
}
},
onMouseleave (e) {
if (this.trigger === 'hover' && !this.pinned) {
if (this.trigger === 'hover' && this.childrenShown.size > 0) {
this.graceTimeout = setTimeout(() => this.hidePopover(), 1)
}
},
@ -245,7 +247,7 @@ const Popover = {
}
},
onMouseleaveContent (e) {
if (this.trigger === 'hover' && !this.pinned) {
if (this.trigger === 'hover' && this.childrenShown.size === 0) {
this.graceTimeout = setTimeout(() => this.hidePopover(), 1)
}
},
@ -260,20 +262,24 @@ const Popover = {
},
onClickOutside (e) {
if (this.hidden) return
if (this.$refs.content.contains(e.target)) return
if (this.$refs.content && this.$refs.content.contains(e.target)) return
if (this.$el.contains(e.target)) return
if (this.childrenShown.size > 0) return
this.hidePopover()
},
onClickContent (e) {
if (this.trigger === 'hover' && this.stayOnClick) {
this.pinned = true
}
if (this.parentPopover) this.parentPopover.onClickOutside(e)
},
onScroll (e) {
this.updateStyles()
},
onResize (e) {
this.updateStyles()
},
onChildPopoverState (childRef, state) {
if (state) {
this.childrenShown.add(childRef)
} else {
this.childrenShown.delete(childRef)
}
}
},
updated () {
@ -292,6 +298,11 @@ const Popover = {
this.$refs.trigger.closest('.mobile-notifications')
if (!scrollable) scrollable = window
this.scrollable = scrollable
let parent = this.$parent
while (parent && parent.$.type.name !== 'Popover') {
parent = parent.$parent
}
this.parentPopover = parent
},
beforeUnmount () {
this.hidePopover()

View file

@ -28,15 +28,6 @@
class="popover-inner"
:close="hidePopover"
/>
<div
v-if="stayOnClick && pinned"
class="pinned-tooltip-icon popover popover-default"
>
<FAIcon
icon="thumbtack"
class="faint"
/>
</div>
</div>
</transition>
</teleport>
@ -61,17 +52,6 @@
box-shadow: var(--popupShadow);
}
.pinned-tooltip-icon {
position: absolute;
top: -1em;
left: -1em;
width: 2em;
height: 2em;
display: flex;
justify-content: center;
align-items: center;
}
.popover-default {
&:after {
content: '';