From 7ad4ef13273bf0900de0735fc5d6e04003c0bfc3 Mon Sep 17 00:00:00 2001 From: Vadim Gorbachev Date: Tue, 7 Mar 2017 13:01:31 +0300 Subject: [PATCH] fix(uiSelectController): calculateContainerWidth use width of ui-select-container not from body, if I set attribute `append-to-body=true` fix(uiSelectController): sizeSearchInput use container width - offsetLeft if updateInVisible fix(uiSelectController): add unit test --- src/uiSelectController.js | 4 ++-- test/select.spec.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index e304279d4..954ada32a 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 eb5b6e594..04c968047 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1925,6 +1925,31 @@ describe('ui-select tests', 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();