Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip Glitchy (#3753) #3914

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(lib): Tooltip did not respond to resize
- Fixes the issue that `Tooltip` did not respond to resizing when it was
  appended to body. Observes changes in the sizes of windown and the
  immediate parent element. See the comment:
    - #3753 (comment)
  • Loading branch information
kikuomax committed Dec 7, 2023
commit 47a32a482cc5e68b7353f408e31499ba8164f5fe
18 changes: 17 additions & 1 deletion src/components/tooltip/Tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export default {
isActive: false,
triggerStyle: {},
timer: null,
_bodyEl: undefined // Used to append to body
_bodyEl: undefined, // Used to append to body
resizeObserver: undefined,
resizeListener: undefined
}
},
computed: {
Expand Down Expand Up @@ -285,6 +287,14 @@ export default {
if (this.appendToBody && typeof window !== 'undefined') {
this.$data._bodyEl = createAbsoluteElement(this.$refs.content)
this.updateAppendToBody()
// observes changes in the window size
this.resizeListener = () => this.updateAppendToBody()
window.addEventListener('resize', this.resizeListener)
// observes changes in the size of the immediate parent
this.resizeObserver = new ResizeObserver(this.resizeListener)
if (this.$el.parentNode != null && this.$el.parentNode.nodeType === Node.ELEMENT_NODE) {
this.resizeObserver.observe(this.$el.parentNode)
}
}
},
created() {
Expand All @@ -298,6 +308,12 @@ export default {
document.removeEventListener('click', this.clickedOutside)
document.removeEventListener('keyup', this.keyPress)
}
if (this.resizeListener != null) {
window.removeEventListener('resize', this.resizeListener)
}
if (this.resizeObserver != null) {
this.resizeObserver.disconnect()
}
if (this.appendToBody) {
removeElement(this.$data._bodyEl)
}
Expand Down