diff --git a/src/nya-bs-select.js b/src/nya-bs-select.js index aa41482..6c417a3 100644 --- a/src/nya-bs-select.js +++ b/src/nya-bs-select.js @@ -342,6 +342,28 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi }; $document.on('click', outClick); + function reset_search() { + searchBox.children().eq(0)[0].value = ""; + var options = dropdownMenu.children(), + length = options.length, + index, + option, + nyaBsOptionNode; + for(index = 0; index < length; index++) { + option = options.eq(index); + if(option.hasClass('nya-bs-option')) { + option.removeClass('not-match'); + } + } + noSearchResult.removeClass('show'); + nyaBsOptionNode = findFocus(true); + + if(nyaBsOptionNode) { + options.removeClass('active'); + jqLite(nyaBsOptionNode).addClass('active'); + } + } + console.log(dropdownToggle[0]==$element.find('button').eq(0)[0]); dropdownToggle.on('blur', function() { @@ -356,6 +378,7 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi calcMenuSize(); } if($attrs.liveSearch === 'true' && $element.hasClass('open')) { + reset_search(); searchBox.children().eq(0)[0].focus(); nyaBsOptionNode = findFocus(true); if(nyaBsOptionNode) { diff --git a/test/spec/live-search-feature.js b/test/spec/live-search-feature.js index e247cea..4976df1 100644 --- a/test/spec/live-search-feature.js +++ b/test/spec/live-search-feature.js @@ -73,4 +73,67 @@ describe('features about live search related, etc;', function() { check(); }); + it('should clear live-search', function() { + // get amount of available li + function get_amount() { + var list = selectElement.find('ul').children(); + var i, k, length = list.length, + liElement, + classList, + check, + counter = 0; + for(i = 0; i < length; i++) { + liElement = list.eq(i); + if(liElement.hasClass('nya-bs-option')) { + classList = liElement[0].classList; + check = false; + for(k = 0; k < classList.length; k++){ + if(classList[k] === 'not-match'){ + check = true; + } + } + if(check === false){ + counter++; + } + } + } + return counter; + } + + // string array + $scope.options = options; + $scope.model = []; + $scope.$digest(); + var selectElement = angular.element('