Skip to content

Commit 077e3f0

Browse files
committedSep 21, 2015
Merge pull request angular-ui#3 from viniciusdacal/issue-2
Issue 2
2 parents 06c318c + 217f70b commit 077e3f0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
 

‎src/uiSelectDirective.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ uis.directive('uiSelect',
4343

4444
$select.onSelectCallback = $parse(attrs.onSelect);
4545
$select.onRemoveCallback = $parse(attrs.onRemove);
46-
46+
4747
//Set reference to ngModel from uiSelectCtrl
4848
$select.ngModel = ngModel;
4949

@@ -190,7 +190,7 @@ uis.directive('uiSelect',
190190

191191
// Support for appending the select field to the body when its open
192192
var appendToBody = scope.$eval(attrs.appendToBody);
193-
if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) {
193+
if ((appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) || attrs.appendTo) {
194194
scope.$watch('$select.open', function(isOpen) {
195195
if (isOpen) {
196196
positionDropdown();
@@ -225,7 +225,11 @@ uis.directive('uiSelect',
225225
originalWidth = element[0].style.width;
226226

227227
// Now move the actual dropdown element to the end of the body
228-
$document.find('body').append(element);
228+
if (attrs.appendTo) {
229+
$document.find(attrs.appendTo).append(element);
230+
}else {
231+
$document.find('body').append(element);
232+
}
229233

230234
element[0].style.position = 'absolute';
231235
element[0].style.left = offset.left + 'px';

‎test/select.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe('ui-select tests', function() {
105105
if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; }
106106
if (attrs.title !== undefined) { attrsHtml += ' title="' + attrs.title + '"'; }
107107
if (attrs.appendToBody != undefined) { attrsHtml += ' append-to-body="' + attrs.appendToBody + '"'; }
108+
if (attrs.appendTo != undefined) { attrsHtml += ' append-to="' + attrs.appendTo + '"'; }
108109
if (attrs.allowClear != undefined) { matchAttrsHtml += ' allow-clear="' + attrs.allowClear + '"';}
109110
}
110111

@@ -1849,6 +1850,23 @@ describe('ui-select tests', function() {
18491850
});
18501851
});
18511852

1853+
describe('select with the appendTo option', function() {
1854+
var body;
1855+
1856+
beforeEach(inject(function($document) {
1857+
body = $document.find('body')[0];
1858+
}));
1859+
1860+
it('should be moved to the end of an element when the appendTo option is a selector', function() {
1861+
var parent = document.createElement('DIV');
1862+
parent.className = 'content-append';
1863+
document.body.appendChild(parent);
1864+
var el = createUiSelect({appendTo: '.content-append'});
1865+
openDropdown(el);
1866+
expect(el.parent()[0]).toBe(parent);
1867+
});
1868+
});
1869+
18521870
describe('select with the append to body option', function() {
18531871
var body;
18541872

0 commit comments

Comments
 (0)