diff --git a/src/uiSelectController.js b/src/uiSelectController.js index cd7d5025c..c6221e65a 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -522,7 +522,7 @@ uis.controller('uiSelectCtrl', ctrl.sizeSearchInput = function() { var input = ctrl.searchInput[0], - container = ctrl.searchInput.parent().parent()[0], + container = ctrl.$element[0], calculateContainerWidth = function() { // Return the container width only if the search input is visible return container.clientWidth * !!input.offsetParent; @@ -531,7 +531,7 @@ uis.controller('uiSelectCtrl', if (containerWidth === 0) { return false; } - var inputWidth = containerWidth - input.offsetLeft - 10; + var inputWidth = containerWidth - input.offsetLeft; if (inputWidth < 50) inputWidth = containerWidth; ctrl.searchInput.css('width', inputWidth+'px'); return true; diff --git a/test/select.spec.js b/test/select.spec.js index 2a8597d74..09b9801a7 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -2037,7 +2037,32 @@ describe('ui-select tests', function () { }); - it('should move to last match when pressing BACKSPACE key from search', function () { + it('should update size of search input use container width', function() { + scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple({ + appendToBody: true + }); + + angular.element(document.body).css("width", "100%"); + angular.element(document.body).css("height", "100%"); + angular.element(document.body).append(el); + + spyOn(el.scope().$select, 'sizeSearchInput'); + + var searchInput = el.find('.ui-select-search'); + el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + + expect(el.scope().$select.sizeSearchInput).toHaveBeenCalled(); + + $timeout.flush(); + + var newWidth = searchInput[0].clientWidth + searchInput[0].offsetLeft; + var containerWidth = el[0].clientWidth; + expect(containerWidth - newWidth).toBeLessThan(10); + + }); + + it('should move to last match when pressing BACKSPACE key from search', function() { var el = createUiSelectMultiple(); var searchInput = el.find('.ui-select-search');