Commit 68eb51e3 authored by peterhegman's avatar peterhegman

Remove tooltip event listeners in `beforeDestroy`

parent 1e5f1eb8
......@@ -91,18 +91,23 @@ export default {
mounted() {
// Temporarily remove `title` attribute from emoji when tooltip is open
// Prevents duplicate tooltips (Bootstrap tooltip and browser title tooltip)
if (this.hasAuthorStatusWithTooltip()) {
const { authorStatus } = this.$refs;
if (authorStatus && authorStatus.querySelector('.has-tooltip')) {
const emoji = authorStatus.querySelector('gl-emoji');
const emojiTitle = emoji.getAttribute('title');
$(this.$refs.authorStatus).on('show.bs.tooltip', () => {
emoji.removeAttribute('title');
});
this.handleAuthorStatusTooltipShow = () => emoji.removeAttribute('title');
this.handleAuthorStatusTooltipHidden = () => emoji.setAttribute('title', emojiTitle);
$(authorStatus).on('show.bs.tooltip', this.handleAuthorStatusTooltipShow);
$(authorStatus).on('hidden.bs.tooltip', this.handleAuthorStatusTooltipHidden);
}
},
beforeDestroy() {
if (this.hasAuthorStatusWithTooltip()) {
const { authorStatus } = this.$refs;
$(this.$refs.authorStatus).on('hidden.bs.tooltip', () => {
emoji.setAttribute('title', emojiTitle);
});
$(authorStatus).off('show.bs.tooltip', this.handleAuthorStatusTooltipShow);
$(authorStatus).off('hidden.bs.tooltip', this.handleAuthorStatusTooltipHidden);
}
},
methods: {
......@@ -125,6 +130,9 @@ export default {
this.isUsernameLinkHovered = false;
},
hasAuthorStatusWithTooltip() {
return this.$refs.authorStatus?.querySelector('.user-status-emoji:not([title=""])');
},
},
};
</script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment