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

Commit 08a0752

Browse files
authored
Merge pull request #1873 from bmsdave/master
fix(uiSelectCtrl) calculateContainerWidth use width of ui-select-container
2 parents 47883ed + b6a17ad commit 08a0752

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/uiSelectController.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ uis.controller('uiSelectCtrl',
522522
ctrl.sizeSearchInput = function() {
523523

524524
var input = ctrl.searchInput[0],
525-
container = ctrl.searchInput.parent().parent()[0],
525+
container = ctrl.$element[0],
526526
calculateContainerWidth = function() {
527527
// Return the container width only if the search input is visible
528528
return container.clientWidth * !!input.offsetParent;
@@ -531,7 +531,7 @@ uis.controller('uiSelectCtrl',
531531
if (containerWidth === 0) {
532532
return false;
533533
}
534-
var inputWidth = containerWidth - input.offsetLeft - 10;
534+
var inputWidth = containerWidth - input.offsetLeft;
535535
if (inputWidth < 50) inputWidth = containerWidth;
536536
ctrl.searchInput.css('width', inputWidth+'px');
537537
return true;

test/select.spec.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,32 @@ describe('ui-select tests', function () {
20372037

20382038
});
20392039

2040-
it('should move to last match when pressing BACKSPACE key from search', function () {
2040+
it('should update size of search input use container width', function() {
2041+
scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha
2042+
var el = createUiSelectMultiple({
2043+
appendToBody: true
2044+
});
2045+
2046+
angular.element(document.body).css("width", "100%");
2047+
angular.element(document.body).css("height", "100%");
2048+
angular.element(document.body).append(el);
2049+
2050+
spyOn(el.scope().$select, 'sizeSearchInput');
2051+
2052+
var searchInput = el.find('.ui-select-search');
2053+
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
2054+
2055+
expect(el.scope().$select.sizeSearchInput).toHaveBeenCalled();
2056+
2057+
$timeout.flush();
2058+
2059+
var newWidth = searchInput[0].clientWidth + searchInput[0].offsetLeft;
2060+
var containerWidth = el[0].clientWidth;
2061+
expect(containerWidth - newWidth).toBeLessThan(10);
2062+
2063+
});
2064+
2065+
it('should move to last match when pressing BACKSPACE key from search', function() {
20412066

20422067
var el = createUiSelectMultiple();
20432068
var searchInput = el.find('.ui-select-search');

0 commit comments

Comments
 (0)