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

Commit 85b560a

Browse files
author
Brian Feister
committed
Merge pull request #712 from cmlenz/fix-input-sizing
Fix issue with the sizing of the text input field
2 parents da159d4 + f76052e commit 85b560a

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/uiSelectController.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -366,29 +366,35 @@ uis.controller('uiSelectCtrl',
366366
return ctrl.placeholder;
367367
};
368368

369-
var containerSizeWatch;
370-
ctrl.sizeSearchInput = function(){
369+
var sizeWatch = null;
370+
ctrl.sizeSearchInput = function() {
371371
var input = _searchInput[0],
372-
container = _searchInput.parent().parent()[0];
373-
_searchInput.css('width','10px');
374-
var calculate = function(){
375-
var newWidth = container.clientWidth - input.offsetLeft - 10;
376-
if(newWidth < 50) newWidth = container.clientWidth;
377-
_searchInput.css('width',newWidth+'px');
378-
};
379-
$timeout(function(){ //Give tags time to render correctly
380-
if (container.clientWidth === 0 && !containerSizeWatch){
381-
containerSizeWatch = $scope.$watch(function(){ return container.clientWidth;}, function(newValue){
382-
if (newValue !== 0){
383-
calculate();
384-
containerSizeWatch();
385-
containerSizeWatch = null;
372+
container = _searchInput.parent().parent()[0],
373+
calculateContainerWidth = function() {
374+
// Return the container width only if the search input is visible
375+
return container.clientWidth * !!input.offsetParent;
376+
},
377+
updateIfVisible = function(containerWidth) {
378+
if (containerWidth === 0) {
379+
return false;
380+
}
381+
var inputWidth = containerWidth - input.offsetLeft - 10;
382+
if (inputWidth < 50) inputWidth = containerWidth;
383+
_searchInput.css('width', inputWidth+'px');
384+
return true;
385+
};
386+
387+
_searchInput.css('width', '10px');
388+
$timeout(function() { //Give tags time to render correctly
389+
if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) {
390+
sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) {
391+
if (updateIfVisible(containerWidth)) {
392+
sizeWatch();
393+
sizeWatch = null;
386394
}
387395
});
388-
}else if (!containerSizeWatch) {
389-
calculate();
390396
}
391-
}, 0, false);
397+
});
392398
};
393399

394400
function _handleDropDownSelection(key) {

src/uiSelectDirective.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ uis.directive('uiSelect',
212212
attrs.$observe('disabled', function() {
213213
// No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string
214214
$select.disabled = attrs.disabled !== undefined ? attrs.disabled : false;
215+
// As the search input field may now become visible, it may be necessary to recompute its size
216+
$select.sizeSearchInput();
215217
});
216218

217219
attrs.$observe('resetSearchInput', function() {

0 commit comments

Comments
 (0)