summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-08-19 09:45:58 +0100
committerBryce <bryce@gitlab.com>2016-08-23 14:44:28 +0200
commit5963263912c1633ff49ce758f71589bae8133e57 (patch)
tree7d090740231b7431cc79da66b44e900742929e5e
parentf633f7db66d4ff42abbe764c21f9da4e49045f91 (diff)
downloadgitlab-ce-5963263912c1633ff49ce758f71589bae8133e57.tar.gz
Fixed enter key in search input not working
Closes #20627
-rw-r--r--app/assets/javascripts/gl_dropdown.js28
-rw-r--r--spec/features/search_spec.rb10
2 files changed, 28 insertions, 10 deletions
diff --git a/app/assets/javascripts/gl_dropdown.js b/app/assets/javascripts/gl_dropdown.js
index 24abea0d30d..b1f5a6816e1 100644
--- a/app/assets/javascripts/gl_dropdown.js
+++ b/app/assets/javascripts/gl_dropdown.js
@@ -31,8 +31,8 @@
this.input
.on('keydown', function (e) {
var keyCode = e.which;
- if (keyCode === 13) {
- e.preventDefault();
+ if (keyCode === 13 && !options.elIsInput) {
+ e.preventDefault()
}
})
.on('keyup', function(e) {
@@ -46,7 +46,7 @@
} else if (this.input.val() === "" && $inputContainer.hasClass(HAS_VALUE_CLASS)) {
$inputContainer.removeClass(HAS_VALUE_CLASS);
}
- if (keyCode === 13) {
+ if (keyCode === 13 && !options.elIsInput) {
return false;
}
if (this.options.remote) {
@@ -238,6 +238,7 @@
}
if (this.options.filterable) {
this.filter = new GitLabDropdownFilter(this.filterInput, {
+ elIsInput: $(this.el).is('input'),
filterInputBlur: this.filterInputBlur,
filterByText: this.options.filterByText,
onFilter: this.options.onFilter,
@@ -266,8 +267,12 @@
if (_this.dropdown.find('.dropdown-toggle-page').length) {
selector = ".dropdown-page-one " + selector;
}
- $(selector, _this.dropdown).first().find('a').addClass('is-focused');
- return currentIndex = 0;
+ if ($(_this.el).is('input')) {
+ currentIndex = -1;
+ } else {
+ $(selector, _this.dropdown).first().find('a').addClass('is-focused');
+ currentIndex = 0;
+ }
}
};
})(this)
@@ -611,17 +616,20 @@
return this.dropdown.before($input);
};
- GitLabDropdown.prototype.selectRowAtIndex = function(index) {
+ GitLabDropdown.prototype.selectRowAtIndex = function() {
var $el, selector;
- selector = SELECTABLE_CLASSES + ":eq(" + index + ") a";
+ selector = ".dropdown-content .is-focused";
if (this.dropdown.find(".dropdown-toggle-page").length) {
selector = ".dropdown-page-one " + selector;
}
$el = $(selector, this.dropdown);
if ($el.length) {
- $el.first().trigger('click');
var href = $el.attr('href');
- if (href && href !== '#') Turbolinks.visit(href);
+ if (href && href !== '#') {
+ Turbolinks.visit(href);
+ } else {
+ $el.first().trigger('click');
+ }
}
};
@@ -657,7 +665,7 @@
return false;
}
if (currentKeyCode === 13 && currentIndex !== -1) {
- return _this.selectRowAtIndex(currentIndex);
+ _this.selectRowAtIndex();
}
};
})(this));
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index b7a25d80fec..dcd3a2f17b0 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -71,6 +71,16 @@ describe "Search", feature: true do
end
describe 'Right header search field', feature: true do
+ it 'allows enter key to search', js: true do
+ visit namespace_project_path(project.namespace, project)
+ fill_in 'search', with: 'gitlab'
+ find('#search').native.send_keys(:enter)
+
+ page.within '.title' do
+ expect(page).to have_content 'Search'
+ end
+ end
+
describe 'Search in project page' do
before do
visit namespace_project_path(project.namespace, project)