Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why md tooltip is not applied to md dummy tab

I am using angular material.

When I create my own directive and add it to md-tab-label, like

<md-tab-label>
<custom-directive>
Label
</cutom-directive>
</md-tab-label>

Then the custom directive is applied to some "md-dummy-tab" also.

But if I give mdtooltop to the md-tab-label ,like

<md-tab-label>
Label
<md-tooltip>Label</md-tooltip>
</md-tab-label>

then there is no md-tooltip applied to "md-dummy-tab" class

I tried searching inside the mdtooltip code, but couldnt get any clue.

https://github.com/angular/material/blob/master/src/components/tooltip/tooltip.js

How can I do the same for my custom directive , ie custom directive should not apply to md dummy tab?

like image 362
Santosh Avatar asked Jul 07 '15 05:07

Santosh


1 Answers

<md-tooltip> is not appended to the <md-dummy-tab> because it doesn't render any HTML code inside the <md-tab-label>. Its template is appended to the nearest parent <md-content> the moment you trigger the tooltip to show.

  scope.$watch('visible', function (isVisible) {
    if (isVisible) showTooltip();
    else hideTooltip();
  });

-

function showTooltip() {
  // Insert the element before positioning it, so we can get the position
  // and check if we should display it
  tooltipParent.append(element);

  // Check if we should display it or not.
  // This handles hide-* and show-* along with any user defined css
  if ( hasComputedStyleValue('display','none') ) {
    scope.visible = false;
    element.detach();
    return;
  }

  positionTooltip();
  angular.forEach([element, background, content], function (element) {
    $animate.addClass(element, 'md-show');
  });
}

-

current       = getNearestContentElement(),
tooltipParent = angular.element(current || document.body)

-

 function getNearestContentElement () {
   var current = element.parent()[0];
   // Look for the nearest parent md-content, stopping at the rootElement.
   while (current && current !== $rootElement[0] && current !== document.body) {
     current = current.parentNode;
   }
   return current;
 }
like image 159
Bartłomiej T. Listwon Avatar answered Sep 21 '22 18:09

Bartłomiej T. Listwon