1

I am trying to use tooltip in my Vue 3 + Boostrap 5 project. However, the moment I implement tooltip, collapse functionality stops working.

I have created a sample page in Stackblitz - https://stackblitz.com/edit/vue-rhm9hw?file=src%2Fcomponents%2FHelloWorld.vue

I am not sure if it is a Vue 3 issue or something I am doing wrong.

I have tried following Adding Bootstrap 5 tooltip to Vue 3 but it hasn't worked for me.

My project is in typescript and thought that trying it in JS might resolve it but I have discovered the same issue in JS too.

4
  • Can you explain what is not working? In your stackblitz, I see the tooltip when hovering over the "Custom Tooltip" button, and when I click on one of the other buttons, the collapsible content becomes visible. What else should happen? Commented Aug 23, 2023 at 20:37
  • @Moritz, the bug is that with the tooltip present, the collapse doesn't toggle anymore (remove the tooltip to see how the collapse should work). On a closer inspection, two toggle events seem to be sent, making the tooltip close and re-open when a button is clicked. Initially I thought the fact there are two controls for it might have something to do with it, but the bug also happens with only one controlling button. Commented Aug 23, 2023 at 21:30
  • @Vivek, at first glance, this looks like a Bootstrap bug. Consider opening an issue on their repo. Meanwhile, the only "fix" in sight is to switch either functionality (collapse or tooltip) to a dedicated plugin. Commented Aug 23, 2023 at 21:41
  • Thanks @tao I have created an issue in Bootstrap's GitHub repo. Hopefully, they'll look at it and address it. Commented Aug 23, 2023 at 22:20

1 Answer 1

0

You haven't instantiated Bootstrap properly. You were using:

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js'; // ❌ nope

instead of

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap'; // ✅ happy days

This seems to fix the error. I haven't looked into why it happens, but my wild guess is some stuff (e.g: collapse!?) gets imported/instantiated more than once.

Demo.


Additionally, I found two more unrelated errors (while I was looking for anything that might cause your problem):

  1. App.vue should not have an id of app on the root element, because the entire app is mounted in the already existing div#app (from public/index.html), which results in the following faulty markup (ids should be unique):
<div id="app">
  <div id="app">
    ... your app here
  </div>
</div>
  1. You seem to be instantiating the Tooltip differently than what the docs are showing 1.
    In the docs, the first param of the Tooltip constructor is always the element selector, not the tooltip container. The container selector (or element) should be passed using the container option.
    I'm quite surprised it works the way you're using it. I beleive the correct way to do it is:
new Tooltip('[data-bs-toggle="tooltip"]', {
  // can be skipped, `document.body` is the default value
  container: document.body,
  // other options, instead of providing them via data-bs-* attributes...
})

1 - Although what you're using seems to produce the desired outcome, I thought I should mention it since it's not complying with the documentation and might stop working at any point.

Sign up to request clarification or add additional context in comments.

1 Comment

You're a star @tao

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.