Skip to content

Commit 7ad4ef1

Browse files
committed
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
1 parent 3e25a48 commit 7ad4ef1

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
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

+25
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,31 @@ describe('ui-select tests', function() {
19251925

19261926
});
19271927

1928+
it('should update size of search input use container width', function() {
1929+
scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha
1930+
var el = createUiSelectMultiple({
1931+
appendToBody: true
1932+
});
1933+
1934+
angular.element(document.body).css("width", "100%");
1935+
angular.element(document.body).css("height", "100%");
1936+
angular.element(document.body).append(el);
1937+
1938+
spyOn(el.scope().$select, 'sizeSearchInput');
1939+
1940+
var searchInput = el.find('.ui-select-search');
1941+
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
1942+
1943+
expect(el.scope().$select.sizeSearchInput).toHaveBeenCalled();
1944+
1945+
$timeout.flush();
1946+
1947+
var newWidth = searchInput[0].clientWidth + searchInput[0].offsetLeft;
1948+
var containerWidth = el[0].clientWidth;
1949+
expect(containerWidth - newWidth).toBeLessThan(10);
1950+
1951+
});
1952+
19281953
it('should move to last match when pressing BACKSPACE key from search', function() {
19291954

19301955
var el = createUiSelectMultiple();

0 commit comments

Comments
 (0)