Charon
Charon

Reputation: 95

Popper.js not working if bootstrap CSS is imported?

I've run into a really unusual issue wherein Popper.js and Tooltip.js are refusing to work if I'm using the Bootstrap CSS.

Here is the code I'm using to test this:

<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<script src="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js"></script>

<span id="test-tooltip" data-tooltip="Testing tooltips!">Hover over me, I dare you.</span>

 <script>
  document.addEventListener('DOMContentLoaded', function() {
    var referenceElement = document.getElementById("test-tooltip");
    var instance = new Tooltip(referenceElement, {
      title: referenceElement.getAttribute('data-tooltip'),
      placement: "bottom",
    });
  });
</script>

There's also some CSS, but it's quite long, so I'll leave that at the bottom.

If I include Bootstrap anywhere, the whole thing just stops working. Nothing shows up at all when hovering.

<link rel="stylesheet" href="CSS/bootstrap.css">

I am using the latest version of bootstrap, and I've even tried a few older versions as well.

Here's the CSS that's being used to style the tooltips:

.popper,
.tooltip {
  position: absolute;
  background: rgb(75, 75, 75);
  color: white;
  min-width: 80px;
  border-radius: 3px;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
  padding: 12px;
  text-align: center;
}
.popper .popper__arrow,
.tooltip .tooltip-arrow {
  width: 0;
  height: 0;
  border-style: solid;
  position: absolute;
  margin: 5px;
}

.tooltip .tooltip-arrow,
.popper .popper__arrow {
  border-color: rgb(75, 75, 75);
}
.popper[x-placement^="top"],
.tooltip[x-placement^="top"] {
  margin-bottom: 6px;
}
.popper[x-placement^="top"] .popper__arrow,
.tooltip[x-placement^="top"] .tooltip-arrow {
  border-width: 5px 5px 0 5px;
  border-left-color: transparent;
  border-right-color: transparent;
  border-bottom-color: transparent;
  bottom: -5px;
  left: calc(50% - 5px);
  margin-top: 0;
  margin-bottom: 0;
}
.popper[x-placement^="bottom"],
.tooltip[x-placement^="bottom"] {
  margin-top: 6px;
}
.tooltip[x-placement^="bottom"] .tooltip-arrow,
.popper[x-placement^="bottom"] .popper__arrow {
  border-width: 0 5px 5px 5px;
  border-left-color: transparent;
  border-right-color: transparent;
  border-top-color: transparent;
  top: -5px;
  left: calc(50% - 5px);
  margin-top: 0;
  margin-bottom: 0;
}
.tooltip[x-placement^="right"],
.popper[x-placement^="right"] {
  margin-left: 6px;
}
.popper[x-placement^="right"] .popper__arrow,
.tooltip[x-placement^="right"] .tooltip-arrow {
  border-width: 5px 5px 5px 0;
  border-left-color: transparent;
  border-top-color: transparent;
  border-bottom-color: transparent;
  left: -5px;
  top: calc(50% - 5px);
  margin-left: 0;
  margin-right: 0;
}
.popper[x-placement^="left"],
.tooltip[x-placement^="left"] {
  margin-right: 6px;
}
.popper[x-placement^="left"] .popper__arrow,
.tooltip[x-placement^="left"] .tooltip-arrow {
  border-width: 5px 0 5px 5px;
  border-top-color: transparent;
  border-right-color: transparent;
  border-bottom-color: transparent;
  right: -6px;
  top: calc(50% - 5px);
  margin-left: 0;
  margin-right: 0;
}

Does anyone know why something this unusual might be happening? Things I have tried:

And many other things, all of which I have forgotten while trying to figure this out.

Upvotes: 1

Views: 3942

Answers (1)

ram pandey
ram pandey

Reputation: 78

I have gone through your code and it's working perfectly, the issue is only with the opacity of tooltip. Add this code to show your tooltip

.tooltip[aria-hidden="false"]{
  opacity:1;
}

Link to working fiddle here

Upvotes: 2

Related Questions