Skip to content

Commit 344e225

Browse files
author
vvo
committed
fix(empty template): hide main empty template as long as we have results
fixes #185
1 parent ca49516 commit 344e225

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/autocomplete/dropdown.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function Dropdown(o) {
6262
_.className(this.cssClasses.prefix, this.cssClasses.empty, true) + '">' +
6363
'</div>');
6464
this.$menu.append(this.$empty);
65+
this.$empty.hide();
6566
}
6667

6768
this.datasets = _.map(o.datasets, function(oDataset) {
@@ -148,6 +149,7 @@ _.mixin(Dropdown.prototype, EventEmitter, {
148149
query: this.datasets[0] && this.datasets[0].query
149150
});
150151
this.$empty.html(html);
152+
this.$empty.show();
151153
this._show();
152154
}
153155
} else if (_.any(this.datasets, hasEmptyTemplate)) {
@@ -162,6 +164,7 @@ _.mixin(Dropdown.prototype, EventEmitter, {
162164
} else if (this.isOpen) {
163165
if (this.$empty) {
164166
this.$empty.empty();
167+
this.$empty.hide();
165168
}
166169

167170
if (query.length >= this.minLength) {

test/unit/dropdown_spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ describe('Dropdown', function() {
9191
it('should include the empty', function() {
9292
expect(this.$menu.find('.aa-empty').length).toEqual(1);
9393
expect(this.$menu.find('.aa-empty').children().length).toEqual(0);
94+
expect(this.$menu.find('.aa-empty').css('display')).toEqual('none');
9495
});
9596

9697
it('should not hide the dropdown if empty', function() {
@@ -102,6 +103,7 @@ describe('Dropdown', function() {
102103
expect(this.$menu.find('.aa-empty').length).toEqual(1);
103104
expect(this.$menu.find('.aa-empty').children().length).toEqual(1);
104105
expect(this.$menu.find('.aa-empty').find('h3.empty').length).toEqual(1);
106+
expect(this.$menu.find('.aa-empty').css('display')).not.toEqual('none');
105107
});
106108

107109
it('should trigger empty', function() {
@@ -126,6 +128,7 @@ describe('Dropdown', function() {
126128
this.view._onRendered('rendered', 'te');
127129

128130
expect(spy).not.toHaveBeenCalled();
131+
expect(this.$menu.find('.aa-empty').css('display')).toEqual('none');
129132
});
130133
});
131134

0 commit comments

Comments
 (0)