Tooltips aren't destroyed on AJAX inserts

Created on 17 April 2021, almost 4 years ago
Updated 13 September 2024, 4 months ago

Problem/Motivation

Tooltips aren't destroyed when their parent elements are.

Steps to reproduce

For example an AJAX View with a pager:

  1. Mouse over the pager button - A tooltip appears
  2. Click the pager button - The View gets replaced via AJAX including the pager button; the old pager button disappears and a new pager button appears in it's place
  3. Mouse off the new button - The tooltip belonging to the old pager button isn't hidden

Proposed resolution

Ensure tooltips are destroyed when their parent elements are.

js/bootstrap.js

  /**
   * Bootstrap Tooltips.
   */
  Drupal.behaviors.bootstrapTooltips = {
    attach: function (context, settings) {
      if (settings.bootstrap && settings.bootstrap.tooltipEnabled) {
        var elements = $(context).find('[data-toggle="tooltip"]').toArray();
        for (var i = 0; i < elements.length; i++) {
          var $element = $(elements[i]);
          var options = $.extend({}, settings.bootstrap.tooltipOptions, $element.data());
          $element.tooltip(options);
+         var tooltip = $element.data('bs.tooltip');
+         $element.on('remove' + '.' + tooltip.type, tooltip.options.selector, $.proxy(tooltip.destroy, tooltip));
        }
      }
    }
  };

Remaining tasks

  • Create patch or merge request
  • Commit

User interface changes

  • Lingering tooltips no longer linger

API changes

  • None

Data model changes

  • None
🐛 Bug report
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom mustanggb Coventry, United Kingdom

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024