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

Commit 8637afc

Browse files
committed
feat(typeahead): change to appendTo
- Change signature to `appendTo`, which takes a value that evaluates to a DOM node for API consistency BREAKING CHANGE: Usage before ```html <div id="typeahead-container"></div> <input typeahead="state for state in states | filter: $viewValue | limitTo: 8" typeahead-append-to-element-id="typeahead-container"> ``` After ```html <div id="typeahead-container"></div> <input typeahead="state for state in states | filter: $viewValue | limitTo: 8" typeahead-append-to="typeaheadContainer"> ``` ```js $scope.typeaheadContainer = angular.element(document.querySelector('#typeaheadContainer')); ``` Closes #4797
1 parent 08ad077 commit 8637afc

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/typeahead/docs/readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ The typeahead directives provide several attributes:
2424
* `typeahead-append-to-body` <i class="glyphicon glyphicon-eye-open"></i>
2525
_(Defaults: false)_ : Should the typeahead popup be appended to $body instead of the parent element?
2626

27-
* `typeahead-append-to-element-id`
28-
_(Defaults: false)_ : Should the typeahead popup be appended to an element id instead of the parent element?
27+
* `typeahead-append-to`
28+
_(Defaults: null)_ : Should the typeahead popup be appended to an element instead of the parent element?
2929

3030
* `typeahead-editable`
3131
_(Defaults: true)_ :
@@ -85,4 +85,4 @@ The typeahead directives provide several attributes:
8585

8686
* `typeahead-show-hint`
8787
_(Defaults: false)_ :
88-
Should input show hint that matches the first option?
88+
Should input show hint that matches the first option?

src/typeahead/test/typeahead.spec.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ describe('typeahead tests', function() {
967967
expect($scope.result).toEqual($scope.states[0]);
968968
});
969969
});
970-
970+
971971
describe('input hint', function() {
972972
var element;
973973

@@ -1047,10 +1047,11 @@ describe('typeahead tests', function() {
10471047
});
10481048
});
10491049

1050-
describe('append to element id', function() {
1050+
describe('append to', function() {
10511051
it('append typeahead results to element', function() {
10521052
$document.find('body').append('<div id="myElement"></div>');
1053-
var element = prepareInputEl('<div><input name="input" ng-model="result" uib-typeahead="item for item in states | filter:$viewValue" typeahead-append-to-element-id="myElement"></div>');
1053+
$scope.myElement = $document.find('#myElement');
1054+
var element = prepareInputEl('<div><input name="input" ng-model="result" uib-typeahead="item for item in states | filter:$viewValue" typeahead-append-to="myElement"></div>');
10541055
changeInputValueTo(element, 'al');
10551056
expect($document.find('#myElement')).toBeOpenWithActive(2, 0);
10561057
$document.find('#myElement').remove();

src/typeahead/typeahead.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
6161

6262
var appendToBody = attrs.typeaheadAppendToBody ? originalScope.$eval(attrs.typeaheadAppendToBody) : false;
6363

64-
var appendToElementId = attrs.typeaheadAppendToElementId || false;
64+
var appendTo = attrs.typeaheadAppendTo ?
65+
originalScope.$eval(attrs.typeaheadAppendTo) : null;
6566

6667
var focusFirst = originalScope.$eval(attrs.typeaheadFocusFirst) !== false;
6768

@@ -423,7 +424,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
423424

424425
originalScope.$on('$destroy', function() {
425426
$document.unbind('click', dismissClickHandler);
426-
if (appendToBody || appendToElementId) {
427+
if (appendToBody || appendTo) {
427428
$popup.remove();
428429
}
429430

@@ -443,8 +444,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
443444

444445
if (appendToBody) {
445446
$document.find('body').append($popup);
446-
} else if (appendToElementId !== false) {
447-
angular.element($document[0].getElementById(appendToElementId)).append($popup);
447+
} else if (appendTo) {
448+
angular.element(appendTo).eq(0).append($popup);
448449
} else {
449450
element.after($popup);
450451
}

0 commit comments

Comments
 (0)