Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide proper documentation for using Tooltip with selector #41020

Open
3 tasks done
axelfontaine opened this issue Nov 9, 2024 · 5 comments
Open
3 tasks done

Provide proper documentation for using Tooltip with selector #41020

axelfontaine opened this issue Nov 9, 2024 · 5 comments

Comments

@axelfontaine
Copy link

Prerequisites

Describe the issue

There is currently no documentation on how to use Tooltip with 'selector' using plain JS.

Reduced test cases

This unfortunately doesn't work:

document.querySelector('body').tooltip({
  allowList: myAllowList,
  selector: '[data-bs-toggle="tooltip"]'
});

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Firefox

What version of Bootstrap are you using?

5.3.3

@nwalters512
Copy link
Contributor

Does the "enable tooltips" example in the docs not meet your needs?

https://getbootstrap.com/docs/5.3/components/tooltips/#enable-tooltips

const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))

If not, it'd be helpful to hear more about exactly what you're trying to achieve.

@axelfontaine
Copy link
Author

@nwalters512 No, as this doesn't take care of elements added dynamically to the page later on.

@nwalters512
Copy link
Contributor

Gotcha. IMO this is outside the realm of what Bootstrap can be expected to document, but I've used https://www.npmjs.com/package/selector-observer for this:

import { observe } from 'selector-observer';

observe('[data-bs-toggle="tooltip"]', {
  add(el) {
    new window.bootstrap.Tooltip(el);
  },
  remove(el) {
    window.bootstrap.Tooltip.getInstance(el)?.dispose();
  },
});

@axelfontaine
Copy link
Author

axelfontaine commented Nov 13, 2024

Well that doesn't really document the selector setting, which from its description, should alleviate the need to pull in another dependency.

@nwalters512
Copy link
Contributor

🙈 never mind; today I learned something new about the Bootstrap API! Yes, it'd be great for this to be formally documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@axelfontaine @nwalters512 @julien-deramond and others