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

fix(uiSelectCtrl) calculateContainerWidth use width of ui-select-container #1873

Merged
merged 2 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down