Andreas Gusakov
Andreas Gusakov

Reputation: 73

Keep material design lite tooltip visible after hover

Is it possible to keep a material design lite tooltip open after hovering over it? So for example a user can click on a link in it.

<div id="myTooltip" class="icon material-icons">info</div>
<div class="mdl-tooltip mdl-tooltip--large" for="myTooltip">
  <a href="#">Here</a> is the further information.
</div>

Upvotes: 2

Views: 581

Answers (1)

benvc
benvc

Reputation: 15130

You can stop the tooltip from being hidden on mouseleave and then handle hiding the tooltip based on whatever other actions you want.

For example:

const tt1 = document.querySelector('#tt1');

tt1.addEventListener('mouseleave', (event) => {
  event.stopImmediatePropagation();
  // handle tooltip hide
});
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Material Design Lite Tooltip</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
  </head>

  <body>

    <!-- Large Tooltip -->
    <div id="tt1" class="icon material-icons">info</div>
    <div class="mdl-tooltip mdl-tooltip--large" for="tt1">
      <a href="#">Link</a><span> followed by text</span>
    </div>

    <script src="https://code.getmdl.io/1.3.0/material.min.js"></script>

  </body>

</html>

Upvotes: 1

Related Questions