Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 845a71f

Browse files
committed
Merge pull request #291 from angular-ui/fix-multiselect-width
fix(multiselect): input width should recalculate correctly when available
2 parents 7a28434 + cfe13b4 commit 845a71f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/select.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,28 @@
388388
return ctrl.placeholder;
389389
};
390390

391+
var containerSizeWatch;
391392
ctrl.sizeSearchInput = function(){
392393
var input = _searchInput[0],
393394
container = _searchInput.parent().parent()[0];
394395
_searchInput.css('width','10px');
395-
$timeout(function(){
396+
var calculate = function(){
396397
var newWidth = container.clientWidth - input.offsetLeft - 10;
397398
if(newWidth < 50) newWidth = container.clientWidth;
398399
_searchInput.css('width',newWidth+'px');
400+
};
401+
$timeout(function(){ //Give tags time to render correctly
402+
if (container.clientWidth === 0 && !containerSizeWatch){
403+
containerSizeWatch = $scope.$watch(function(){ return container.clientWidth;}, function(newValue){
404+
if (newValue !== 0){
405+
calculate();
406+
containerSizeWatch();
407+
containerSizeWatch = null;
408+
}
409+
});
410+
}else if (!containerSizeWatch) {
411+
calculate();
412+
}
399413
}, 0, false);
400414
};
401415

@@ -919,7 +933,7 @@
919933
});
920934

921935
if($select.multiple){
922-
$select.sizeSearchInput();
936+
$select.sizeSearchInput();
923937
}
924938

925939
}

test/select.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,14 @@ describe('ui-select tests', function() {
10831083
it('should update size of search input after removing an item', function() {
10841084
scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha
10851085
var el = createUiSelectMultiple();
1086+
1087+
spyOn(el.scope().$select, 'sizeSearchInput');
1088+
10861089
var searchInput = el.find('.ui-select-search');
10871090
var oldWidth = searchInput.css('width');
1088-
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
10891091

1090-
$timeout.flush();
1091-
expect(oldWidth).not.toBe(searchInput.css('width'));
1092+
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
1093+
expect(el.scope().$select.sizeSearchInput).toHaveBeenCalled();
10921094

10931095
});
10941096

0 commit comments

Comments
 (0)