Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 2a1aaf2

Browse files
committed
feat(tooltip): add appendToBody only attribute support
- Add support for using only `tooltip-append-to-body` without any attribute value to enable appending tooltip to body Closes #4945 Closes #5071
1 parent a49ce8e commit 2a1aaf2

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

src/popover/docs/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ will display:
4242
- `popover-trigger`: What should trigger the show of the popover? See the
4343
`tooltip` directive for supported values.
4444
- `popover-append-to-body`_(Default: false)_: Should the popover be appended to `$body` instead of
45-
the parent element? Note that the presence of this attribute without a value implies `true`.
45+
the parent element?
4646
- `popover-is-open` <i class="glyphicon glyphicon-eye-open"></i>
4747
_(Default: false)_:
4848
Whether to show the popover.

src/tooltip/docs/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ will display:
4040
- `tooltip-enable`: Is it enabled? It will enable or disable the configured
4141
`tooltip-trigger`.
4242
- `tooltip-append-to-body`_(Default: false)_: Should the tooltip be appended to `$body` instead of
43-
the parent element? Note that the presence of this attribute without a value implies `true`.
43+
the parent element?
4444
- `tooltip-class`: Custom class to be applied to the tooltip.
4545
- `tooltip-is-open` <i class="glyphicon glyphicon-eye-open"></i>
4646
_(Default: false)_:

src/tooltip/test/tooltip.spec.js

+42
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,48 @@ describe('$uibTooltipProvider', function() {
966966
expect($body.children().length).toEqual(bodyLength + 1);
967967
}));
968968

969+
it('should append to the body when only attribute present', inject(function($rootScope, $compile, $document) {
970+
$body = $document.find('body');
971+
elmBody = angular.element(
972+
'<div><span uib-tooltip="tooltip text" tooltip-append-to-body>Selector Text</span></div>'
973+
);
974+
975+
scope = $rootScope;
976+
$compile(elmBody)(scope);
977+
scope.$digest();
978+
elm = elmBody.find('span');
979+
elmScope = elm.scope();
980+
tooltipScope = elmScope.$$childTail;
981+
982+
var bodyLength = $body.children().length;
983+
trigger(elm, 'mouseenter');
984+
985+
expect(tooltipScope.isOpen).toBe(true);
986+
expect(elmBody.children().length).toBe(1);
987+
expect($body.children().length).toEqual(bodyLength + 1);
988+
}));
989+
990+
it('should not append to the body when attribute value is false', inject(function($rootScope, $compile, $document) {
991+
$body = $document.find('body');
992+
elmBody = angular.element(
993+
'<div><span uib-tooltip="tooltip text" tooltip-append-to-body="false">Selector Text</span></div>'
994+
);
995+
996+
scope = $rootScope;
997+
$compile(elmBody)(scope);
998+
scope.$digest();
999+
elm = elmBody.find('span');
1000+
elmScope = elm.scope();
1001+
tooltipScope = elmScope.$$childTail;
1002+
1003+
var bodyLength = $body.children().length;
1004+
trigger(elm, 'mouseenter');
1005+
1006+
expect(tooltipScope.isOpen).toBe(true);
1007+
expect(elmBody.children().length).toBe(2);
1008+
expect($body.children().length).toEqual(bodyLength);
1009+
}));
1010+
9691011
it('should close on location change', inject(function($rootScope, $compile) {
9701012
elmBody = angular.element(
9711013
'<div><span uib-tooltip="tooltip text">Selector Text</span></div>'

src/tooltip/tooltip.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,14 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
533533
var animation = scope.$eval(attrs[prefix + 'Animation']);
534534
ttScope.animation = angular.isDefined(animation) ? !!animation : options.animation;
535535

536-
var appendToBodyVal = scope.$eval(attrs[prefix + 'AppendToBody']);
536+
var appendToBodyVal;
537+
var appendKey = prefix + 'AppendToBody';
538+
if (appendKey in attrs && attrs[appendKey] === undefined) {
539+
appendToBodyVal = true;
540+
} else {
541+
appendToBodyVal = scope.$eval(attrs[appendKey]);
542+
}
543+
537544
appendToBody = angular.isDefined(appendToBodyVal) ? appendToBodyVal : appendToBody;
538545

539546
// if a tooltip is attached to <body> we need to remove it on

0 commit comments

Comments
 (0)