Skip to content

Commit

Permalink
fix(empty template): hide main empty template as long as we have results
Browse files Browse the repository at this point in the history
fixes #185
  • Loading branch information
vvo committed Jun 22, 2017
1 parent ca49516 commit 344e225
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/autocomplete/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function Dropdown(o) {
_.className(this.cssClasses.prefix, this.cssClasses.empty, true) + '">' +
'</div>');
this.$menu.append(this.$empty);
this.$empty.hide();
}

this.datasets = _.map(o.datasets, function(oDataset) {
Expand Down Expand Up @@ -148,6 +149,7 @@ _.mixin(Dropdown.prototype, EventEmitter, {
query: this.datasets[0] && this.datasets[0].query
});
this.$empty.html(html);
this.$empty.show();
this._show();
}
} else if (_.any(this.datasets, hasEmptyTemplate)) {
Expand All @@ -162,6 +164,7 @@ _.mixin(Dropdown.prototype, EventEmitter, {
} else if (this.isOpen) {
if (this.$empty) {
this.$empty.empty();
this.$empty.hide();
}

if (query.length >= this.minLength) {
Expand Down
3 changes: 3 additions & 0 deletions test/unit/dropdown_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('Dropdown', function() {
it('should include the empty', function() {
expect(this.$menu.find('.aa-empty').length).toEqual(1);
expect(this.$menu.find('.aa-empty').children().length).toEqual(0);
expect(this.$menu.find('.aa-empty').css('display')).toEqual('none');
});

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

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

expect(spy).not.toHaveBeenCalled();
expect(this.$menu.find('.aa-empty').css('display')).toEqual('none');
});
});

Expand Down

0 comments on commit 344e225

Please sign in to comment.