question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tooltip] Tooltip does not vanish after route navigation with reusable routes

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

A displayed tooltip should vanish, after navigating to a route with a different component.

What is the current behavior?

When a RouteReuseStrategy is implemented, then the tooltip doesn’t vanish if the original route is detached while the tooltip was visible.

What are the steps to reproduce?

StackBlitz example: https://stackblitz.com/edit/angular-yvcjzp

A tooltip is displayed on button “Goto Page 2”. Clicking on the button will navigate to page 2. This will causes the tooltip from page 1 to be stuck on the screen. It will only vanish once the user navigates back to page 1 again.

Disabling reusable routes by removing the custom RouteReuseStrategy will lead to the the expected behavior again:

providers: [
    // remove this, and the tooltip starts to work properly
    { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
  ],

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

“dependencies”: { “@angular/animations”: “6.0.0”, “@angular/cdk”: “^6.0.0”, “@angular/common”: “6.0.0”, “@angular/compiler”: “6.0.0”, “@angular/core”: “6.0.0”, “@angular/forms”: “6.0.0”, “@angular/http”: “6.0.0”, “@angular/material”: “^6.0.0”, “@angular/platform-browser”: “6.0.0”, “@angular/platform-browser-dynamic”: “6.0.0”, “@angular/router”: “6.0.0”, “core-js”: “^2.4.1”, “rxjs”: “^6.1.0”, “rxjs-compat”: “^6.1.0”, “zone.js”: “^0.8.26” },

Is there anything else we should know?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:16
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
vinothsubramaniancommented, Sep 11, 2018

@nharrer Thanks for the work around.

I am not very sure it is right way do native. But it worked for me inside RouteReuseStrategy -> store method

while(document.getElementsByTagName('mat-tooltip-component').length > 0) { document.getElementsByTagName('mat-tooltip-component')[0].remove(); }

Workaround StackBlitz

6reactions
princemaplecommented, Aug 10, 2021

Another take on this one… On navigation start, detach the tooltip overlay. I tried to hide it via MatTooltip.hide() but for some reason the tooltip just doesn’t go away.

import {Directive, Injectable, OnDestroy, OnInit} from '@angular/core';
import {MatTooltip} from '@angular/material/tooltip';
import {NavigationStart, Router} from '@angular/router';

import {filter} from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class TooltipCollector {
  collection = new Set<MatTooltip>();

  constructor(router: Router) {
    router.events.pipe(filter(e => e instanceof NavigationStart)).subscribe(() => {
      for (let mt of this.collection) {
        if (mt._tooltipInstance?.isVisible()) {
          mt._overlayRef?.detach();
          break;
        }
      }
    });
  }
}

@Directive({
  selector: '[matTooltip]',
})
export class HideTooltipDirective implements OnInit, OnDestroy {
  constructor(private mt: MatTooltip, private tc: TooltipCollector) {}

  ngOnInit() {
    this.tc.collection.add(this.mt);
  }

  ngOnDestroy() {
    this.tc.collection.delete(this.mt);
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Tooltip] Tooltip does not vanish after route navigation with reusable ...
What is the expected behavior? A displayed tooltip should vanish, after navigating to a route with a different component. What is the current...
Read more >
Issues with Angular Material MatTooltip when navigating to a ...
When I run the site, I see the tooltips for the buttons in app.component.html but when I click on the module buttons I...
Read more >
Fix list for IBM Business Automation Workflow
APAR/Known Issue Security Title JR65073 X MULTIPLE SECURITY VULNERABILITIES IN SWAGGER UI DT143805 FIX FOR JR64316 IS INCOMPLETE DT143824 PDW PRUNE FAILS WITH A SQL EXCEPTION...
Read more >
React Native Navigation: Tutorial with examples
React Navigation is written in JavaScript and does not directly use the native ... The code used to implement routing in both libraries...
Read more >
US7142205B2 - Single gesture map navigation graphical user ...
A further tap of the ToolTip may result in the navigation to a link or URL ... Map navigation may be particularly difficult...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found