summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-07-26 20:57:00 +0000
committerFatih Acet <acetfatih@gmail.com>2016-07-26 20:57:00 +0000
commit7ee7567a59a0f541eee7e88b405c06389db801b8 (patch)
tree463c65f7286a7e322da54ec955152035ca5e484e
parentc4457857f69017ff531276e86c8a0902f1cd70b6 (diff)
parent20f932d768700f073a1ed5b0d6789c31ab41499b (diff)
downloadgitlab-ce-7ee7567a59a0f541eee7e88b405c06389db801b8.tar.gz
Merge branch 'search-autocomplete-enter-fix' into '8-10-stable'
Fixed issue with autocomplete search not working with enter key ## What does this MR do? Fixes an issue that was stopping the enter key from searching in the top search bar. ## What are the relevant issue numbers? Closes #20165 ps. Once this is merged - i'll create a MR against master with the JS changes. See merge request !5466
-rw-r--r--app/assets/javascripts/gl_dropdown.js.coffee16
-rw-r--r--app/assets/javascripts/search_autocomplete.js.coffee1
-rw-r--r--spec/features/search_spec.rb10
3 files changed, 21 insertions, 6 deletions
diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee
index 7086ece29b8..73164cdce1d 100644
--- a/app/assets/javascripts/gl_dropdown.js.coffee
+++ b/app/assets/javascripts/gl_dropdown.js.coffee
@@ -218,12 +218,15 @@ class GitLabDropdown
if @dropdown.find('.dropdown-toggle-page').length
selector = ".dropdown-page-one #{selector}"
- $(selector, @dropdown)
- .first()
- .find('a')
- .addClass('is-focused')
+ if not $(@el).is('input')
+ $(selector, @dropdown)
+ .first()
+ .find('a')
+ .addClass('is-focused')
- currentIndex = 0
+ currentIndex = 0
+ else
+ currentIndex = -1
# Event listeners
@@ -559,10 +562,11 @@ class GitLabDropdown
# simulate a click on the first link
$el = $(selector, @dropdown)
- if $el.length
+ if $el.length and currentIndex > -1
e.preventDefault()
e.stopImmediatePropagation()
$el.first().trigger('click')
+ $el.first().get(0).click?()
addArrowKeyEvent: ->
ARROW_KEY_CODES = [38, 40]
diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee
index 72b1d3dfb1e..2c83bc0d5fe 100644
--- a/app/assets/javascripts/search_autocomplete.js.coffee
+++ b/app/assets/javascripts/search_autocomplete.js.coffee
@@ -63,6 +63,7 @@ class @SearchAutocomplete
data: @getData.bind(@)
selectable: true
clicked: @onClick.bind(@)
+ id: (data) -> _.escape(data.text)
getData: (term, callback) ->
_this = @
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index d0a301038c4..83e8a62793f 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -51,6 +51,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)