From 94edc17b690ea67f53eaa127c7e84c62c4e5b97d Mon Sep 17 00:00:00 2001 From: Vinicius Dacal Date: Mon, 21 Sep 2015 11:08:34 -0300 Subject: [PATCH 1/2] created appendTo option --- src/uiSelectDirective.js | 14 +++++++++++--- test/select.spec.js | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 76df08b67..c699a7f17 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -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; @@ -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(); @@ -199,10 +199,14 @@ uis.directive('uiSelect', } }); + // $document.bind('scroll', function() { + // positionDropdown(); + // }); // Move the dropdown back to its original location when the scope is destroyed. Otherwise // it might stick around when the user routes away or the select field is otherwise removed scope.$on('$destroy', function() { resetDropdown(); + //$document.unbind('scroll'); }); } @@ -225,7 +229,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'; diff --git a/test/select.spec.js b/test/select.spec.js index d502040b4..808a291a7 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -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 + '"';} } @@ -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; From 217f70bc91c92951918eea351a22a0eeff7048fe Mon Sep 17 00:00:00 2001 From: Vinicius Dacal Date: Mon, 21 Sep 2015 11:17:10 -0300 Subject: [PATCH 2/2] removed unused code --- src/uiSelectDirective.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index c699a7f17..ed22e7304 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -199,14 +199,10 @@ uis.directive('uiSelect', } }); - // $document.bind('scroll', function() { - // positionDropdown(); - // }); // Move the dropdown back to its original location when the scope is destroyed. Otherwise // it might stick around when the user routes away or the select field is otherwise removed scope.$on('$destroy', function() { resetDropdown(); - //$document.unbind('scroll'); }); }