Drupal Radix Theme
  • Introduction
    • Overview & Support
  • Installation
    • Requirements
    • Getting Started
    • Setup with ddev
  • Understanding Radix
    • Individual files and directories
    • Bootstrap Build
    • Bootswatch
  • Working with the components
    • Components: Intro
    • Components: A deep dive
    • An example component
    • The drupal-radix-cli
    • Copy and modify a component
  • Components
    • Accordion
    • Alerts
    • Badge
    • Block
    • Buttons
    • Button Group
    • Breadcrumb
    • Card
    • Carousel
    • Close button
    • Comment
    • Collapse
    • Details
    • Dropdown menu
    • Field
    • Field Comment
    • Fieldset
    • Figure
    • Form
    • Form: Element
    • Form Element Label
    • Form Element: Radio Checkbox
    • Heading
    • HTML
    • Image
    • Input
    • List group
    • Local Tasks
    • Media
    • Modal
    • Nav
    • Nav Item
    • Navbar
    • Navbar Brand
    • Node
    • Offcanvas
    • Page
    • Page: Content
    • Page: Footer
    • Page: Navigation
    • Page: Title
    • Pagination
    • Progress
    • Radios
    • Region
    • Select
    • Spinners
    • Table
    • Taxonomy
    • Textarea
    • Toasts
    • Tooltips
    • User
    • Views: view
    • Views: view--grid
    • Views: view--table
    • Views: view--unformatted
  • Misc
    • Migration and upgrading
    • Roadmap
    • Credits & Contributions
Powered by GitBook
On this page
  • Considerations
  • Usage

Was this helpful?

  1. Components

Tooltips

Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage.

PreviousToastsNextUser

Last updated 10 months ago

Was this helpful?

Considerations

  • Tooltips rely on the third party library for positioning.

  • Tooltips are opt-in for performance reasons, so you must initialize them yourself.

Usage

For using the Tooltip, you don't necessarily need a specific twig template, you just need to trigger the tooltip on any element that has data-bs-toggle="tooltip and and associated data-bs-title="Default tooltip" .

Taken from the Bootstrap Tooltip component page example, you can trigger the Tooltip on a link with a markup like below:

<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" data-bs-title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" data-bs-title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" data-bs-title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" data-bs-title="The last tip!">your own</a> site or project.</p>

and then trigger it with the following javascript init, note that this file already exists in _bootstrap.js, uncomment if not needed:

import Tooltip from 'bootstrap/js/dist/tooltip';

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

Bootstrap docs
Floating UI (previously PopperJS)