Commit 7ee7567a authored by Fatih Acet's avatar Fatih Acet

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
parents c4457857 20f932d7
...@@ -218,12 +218,15 @@ class GitLabDropdown ...@@ -218,12 +218,15 @@ class GitLabDropdown
if @dropdown.find('.dropdown-toggle-page').length if @dropdown.find('.dropdown-toggle-page').length
selector = ".dropdown-page-one #{selector}" selector = ".dropdown-page-one #{selector}"
if not $(@el).is('input')
$(selector, @dropdown) $(selector, @dropdown)
.first() .first()
.find('a') .find('a')
.addClass('is-focused') .addClass('is-focused')
currentIndex = 0 currentIndex = 0
else
currentIndex = -1
# Event listeners # Event listeners
...@@ -559,10 +562,11 @@ class GitLabDropdown ...@@ -559,10 +562,11 @@ class GitLabDropdown
# simulate a click on the first link # simulate a click on the first link
$el = $(selector, @dropdown) $el = $(selector, @dropdown)
if $el.length if $el.length and currentIndex > -1
e.preventDefault() e.preventDefault()
e.stopImmediatePropagation() e.stopImmediatePropagation()
$el.first().trigger('click') $el.first().trigger('click')
$el.first().get(0).click?()
addArrowKeyEvent: -> addArrowKeyEvent: ->
ARROW_KEY_CODES = [38, 40] ARROW_KEY_CODES = [38, 40]
......
...@@ -63,6 +63,7 @@ class @SearchAutocomplete ...@@ -63,6 +63,7 @@ class @SearchAutocomplete
data: @getData.bind(@) data: @getData.bind(@)
selectable: true selectable: true
clicked: @onClick.bind(@) clicked: @onClick.bind(@)
id: (data) -> _.escape(data.text)
getData: (term, callback) -> getData: (term, callback) ->
_this = @ _this = @
......
...@@ -51,6 +51,16 @@ describe "Search", feature: true do ...@@ -51,6 +51,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