14

before posting here i searched and searched and i found several solutions for applying tooltips to disabled buttons, anyway none of these was using uib-tooltip from angular ui bootstrap.

Here is the code of my button:

<button class="btn btn-default"
        uib-tooltip="My tooltip text"
        tooltip-append-to-body="true"
        ng-disabled="!isAllSelected"
        ng-click="doThat()">Click Here
</button>

Do you know how to make tooltip displayable even when the button is disabled?

smartmouse
  • 13,912
  • 34
  • 100
  • 166
  • I dont think it will work as if button is disabled no event will get fired. Better is disable button using CSS by adding class. – Ved Mar 02 '16 at 10:26
  • you should wrap the button into an element. after that you can activate the tooltip for the element. – Hans Apr 20 '16 at 06:36

5 Answers5

9

Similar to janosch's solution - wrap your button in a div which has the tooltip attribute.

<div uib-tooltip="{{ isDisabled ? 'Button is disabled' : '' }}">
   <button disabled="isDisabled">Button</button>
</div>

The tooltip will only be visible when the variable isDisabled is true, which also sets the disabled status of the button.

This solution will also work if you are using the title attribute instead of uib-tooltip

brooklynDadCore
  • 1,309
  • 8
  • 13
  • 2
    Make sure to disable the pointer-events, as demonstrated in this answer. Otherwise the tooltip will not work properly: https://stackoverflow.com/a/40147917/2698694 – Connor M Jul 09 '20 at 19:43
3

I don't think it's possible on a button, but it works if you use link disguised as a button, instead of a button:

<a class="btn btn-default"
   uib-tooltip="My tooltip text"
   tooltip-append-to-body="true"
   ng-disabled="!isAllSelected"
   ng-click="doThat()">Click Here
</a>
prograde
  • 2,620
  • 2
  • 23
  • 32
2

Simplest, least intrusive solution to this is:

<a class="btn btn-default"
    uib-tooltip="My tooltip text"
    tooltip-append-to-body="true"
    ng-disabled="!isAllSelected"
    ng-click="isAllSelected ? doThat() : null">Click Here
</a>

(notice conditional ng-click, without which clicks will still go through even when anchor is "disabled" - i.e. anchors don't support disabled attribute)

d3vtoolsmith
  • 151
  • 1
  • 10
2

I know this question is several years old however someone might find useful this workaround.

What I did was to wrap the button content in a <span> tag and apply the uib-tooltip to it:

<button type="button" class="btn btn-primary" ng-click="foo()" ng-disabled="true">
    <span uib-tooltip="Tooltip text" tooltip-append-to-body="true"> Button text<span>
</button>

If you also need the tooltip to be shown when the user hovers over the whole button area, you can also remove the button padding and add it to the <span> instead.

<button type="button" class="btn btn-primary" ng-click="foo()" ng-disabled="true" style="padding: 0px !important;">
    <span uib-tooltip="Tooltip text" tooltip-append-to-body="true" style="display:inline-block; padding: 5px 10px;"> Button text<span>
</button> 
janosch
  • 21
  • 2
-1

Irrespective of button being enabled or disabled, I am getting the uib tool tip. The below code is working fine for me.

<button type="button" class="btn btn-sm btn-default" ng-click="toggleMin()" ng-disabled = "true" uib-tooltip="After today restriction" >Min date</button>

Please see this plunker

Added screenshot of tooltip enter image description here

Additional notes: You can also configure the position of tooltip. All you need to do is to take the help of $uibTooltipProvider. We can then use config section to achieve the result. Below code is included in the plunker.

angular.module('ui.bootstrap.demo')
.config(['$uibTooltipProvider', function ($uibTooltipProvider) {
    $uibTooltipProvider.options({
        'placement':'bottom'
    });
}])
Naga Sandeep
  • 1,421
  • 2
  • 13
  • 26