Commit 9b079219 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'gl-dropdown-enter' into 'master'

Fixed enter key in search input not working

## What does this MR do?

Fixes a bug where the enter key wouldn't search in the top nav search input

Closes #20627 

See merge request !5888
parents f633f7db 86f03e17
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
this.input this.input
.on('keydown', function (e) { .on('keydown', function (e) {
var keyCode = e.which; var keyCode = e.which;
if (keyCode === 13) { if (keyCode === 13 && !options.elIsInput) {
e.preventDefault(); e.preventDefault()
} }
}) })
.on('keyup', function(e) { .on('keyup', function(e) {
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
} else if (this.input.val() === "" && $inputContainer.hasClass(HAS_VALUE_CLASS)) { } else if (this.input.val() === "" && $inputContainer.hasClass(HAS_VALUE_CLASS)) {
$inputContainer.removeClass(HAS_VALUE_CLASS); $inputContainer.removeClass(HAS_VALUE_CLASS);
} }
if (keyCode === 13) { if (keyCode === 13 && !options.elIsInput) {
return false; return false;
} }
if (this.options.remote) { if (this.options.remote) {
...@@ -238,6 +238,7 @@ ...@@ -238,6 +238,7 @@
} }
if (this.options.filterable) { if (this.options.filterable) {
this.filter = new GitLabDropdownFilter(this.filterInput, { this.filter = new GitLabDropdownFilter(this.filterInput, {
elIsInput: $(this.el).is('input'),
filterInputBlur: this.filterInputBlur, filterInputBlur: this.filterInputBlur,
filterByText: this.options.filterByText, filterByText: this.options.filterByText,
onFilter: this.options.onFilter, onFilter: this.options.onFilter,
...@@ -266,8 +267,12 @@ ...@@ -266,8 +267,12 @@
if (_this.dropdown.find('.dropdown-toggle-page').length) { if (_this.dropdown.find('.dropdown-toggle-page').length) {
selector = ".dropdown-page-one " + selector; selector = ".dropdown-page-one " + selector;
} }
if ($(_this.el).is('input')) {
currentIndex = -1;
} else {
$(selector, _this.dropdown).first().find('a').addClass('is-focused'); $(selector, _this.dropdown).first().find('a').addClass('is-focused');
return currentIndex = 0; currentIndex = 0;
}
} }
}; };
})(this) })(this)
...@@ -613,15 +618,23 @@ ...@@ -613,15 +618,23 @@
GitLabDropdown.prototype.selectRowAtIndex = function(index) { GitLabDropdown.prototype.selectRowAtIndex = function(index) {
var $el, selector; var $el, selector;
// If we pass an option index
if (typeof index !== "undefined") {
selector = SELECTABLE_CLASSES + ":eq(" + index + ") a"; selector = SELECTABLE_CLASSES + ":eq(" + index + ") a";
} else {
selector = ".dropdown-content .is-focused";
}
if (this.dropdown.find(".dropdown-toggle-page").length) { if (this.dropdown.find(".dropdown-toggle-page").length) {
selector = ".dropdown-page-one " + selector; selector = ".dropdown-page-one " + selector;
} }
$el = $(selector, this.dropdown); $el = $(selector, this.dropdown);
if ($el.length) { if ($el.length) {
$el.first().trigger('click');
var href = $el.attr('href'); var href = $el.attr('href');
if (href && href !== '#') Turbolinks.visit(href); if (href && href !== '#') {
Turbolinks.visit(href);
} else {
$el.first().trigger('click');
}
} }
}; };
...@@ -657,7 +670,7 @@ ...@@ -657,7 +670,7 @@
return false; return false;
} }
if (currentKeyCode === 13 && currentIndex !== -1) { if (currentKeyCode === 13 && currentIndex !== -1) {
return _this.selectRowAtIndex(currentIndex); _this.selectRowAtIndex();
} }
}; };
})(this)); })(this));
......
...@@ -71,6 +71,16 @@ describe "Search", feature: true do ...@@ -71,6 +71,16 @@ describe "Search", feature: true do
end end
describe 'Right header search field', feature: true do 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 describe 'Search in project page' do
before do before do
visit namespace_project_path(project.namespace, project) visit namespace_project_path(project.namespace, project)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment