Skip to content

Commit

Permalink
Merge pull request angular-ui#3 from viniciusdacal/issue-2
Browse files Browse the repository at this point in the history
Issue 2
  • Loading branch information
viniciusdacal committed Sep 21, 2015
2 parents 06c318c + 217f70b commit 077e3f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uis.directive('uiSelect',

$select.onSelectCallback = $parse(attrs.onSelect);
$select.onRemoveCallback = $parse(attrs.onRemove);

//Set reference to ngModel from uiSelectCtrl
$select.ngModel = ngModel;

Expand Down Expand Up @@ -190,7 +190,7 @@ uis.directive('uiSelect',

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

// Now move the actual dropdown element to the end of the body
$document.find('body').append(element);
if (attrs.appendTo) {
$document.find(attrs.appendTo).append(element);
}else {
$document.find('body').append(element);
}

element[0].style.position = 'absolute';
element[0].style.left = offset.left + 'px';
Expand Down
18 changes: 18 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('ui-select tests', function() {
if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; }
if (attrs.title !== undefined) { attrsHtml += ' title="' + attrs.title + '"'; }
if (attrs.appendToBody != undefined) { attrsHtml += ' append-to-body="' + attrs.appendToBody + '"'; }
if (attrs.appendTo != undefined) { attrsHtml += ' append-to="' + attrs.appendTo + '"'; }
if (attrs.allowClear != undefined) { matchAttrsHtml += ' allow-clear="' + attrs.allowClear + '"';}
}

Expand Down Expand Up @@ -1849,6 +1850,23 @@ describe('ui-select tests', function() {
});
});

describe('select with the appendTo option', function() {
var body;

beforeEach(inject(function($document) {
body = $document.find('body')[0];
}));

it('should be moved to the end of an element when the appendTo option is a selector', function() {
var parent = document.createElement('DIV');
parent.className = 'content-append';
document.body.appendChild(parent);
var el = createUiSelect({appendTo: '.content-append'});
openDropdown(el);
expect(el.parent()[0]).toBe(parent);
});
});

describe('select with the append to body option', function() {
var body;

Expand Down

0 comments on commit 077e3f0

Please sign in to comment.