diff options
author | Jacob Schatz <jschatz@gitlab.com> | 2016-06-29 19:22:08 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2016-06-29 19:22:08 +0000 |
commit | c051630aa88d3394a77108aa8ad422c91b0aec9f (patch) | |
tree | 6716876206e37bbd2330744639c3cba70f3a167a | |
parent | c8e4fe5625f7dc141ed2b7c0ffb09084f2289f7d (diff) | |
parent | e1d38bc963a64ea8de51d7840a91219d57600ae6 (diff) | |
download | gitlab-ce-c051630aa88d3394a77108aa8ad422c91b0aec9f.tar.gz |
Merge branch 'search-input-blur' into 'master'
Fixed search field blur not removing focus
## What does this MR do?
Adds a blur event to remove focus styling from the search input.
Any particular reason we were looking for clicks on the document? I can't see why we would be.
## What are the relevant issue numbers?
Closes #18670
## Screenshots (if relevant)
![tab](/uploads/4c74d4f76ec7b45bfcf581606d2defb5/tab.gif)
See merge request !4704
-rw-r--r-- | app/assets/javascripts/gl_dropdown.js.coffee | 7 | ||||
-rw-r--r-- | app/assets/javascripts/search_autocomplete.js.coffee | 11 |
2 files changed, 8 insertions, 10 deletions
diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 1b0d9f0b1ae..ed9dfcc917e 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -220,6 +220,13 @@ class GitLabDropdown @dropdown.on 'keyup', (e) => if e.which is 27 # Escape key $('.dropdown-menu-close', @dropdown).trigger 'click' + @dropdown.on 'blur', 'a', (e) => + if e.relatedTarget? + $relatedTarget = $(e.relatedTarget) + $dropdownMenu = $relatedTarget.closest('.dropdown-menu') + + if $dropdownMenu.length is 0 + @dropdown.removeClass('open') if @dropdown.find(".dropdown-toggle-page").length @dropdown.find(".dropdown-toggle-page, .dropdown-menu-back").on "click", (e) => diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee index 421328554b8..72b1d3dfb1e 100644 --- a/app/assets/javascripts/search_autocomplete.js.coffee +++ b/app/assets/javascripts/search_autocomplete.js.coffee @@ -171,22 +171,15 @@ class @SearchAutocomplete } bindEvents: -> - $(document).on 'click', @onDocumentClick @searchInput.on 'keydown', @onSearchInputKeyDown @searchInput.on 'keyup', @onSearchInputKeyUp @searchInput.on 'click', @onSearchInputClick @searchInput.on 'focus', @onSearchInputFocus + @searchInput.on 'blur', @onSearchInputBlur @clearInput.on 'click', @onClearInputClick @locationBadgeEl.on 'click', => @searchInput.focus() - onDocumentClick: (e) => - # If clicking outside the search box - # And search input is not focused - # And we are not clicking inside a suggestion - if not $.contains(@dropdown[0], e.target) and @isFocused and not $(e.target).closest('.search-form').length - @onSearchInputBlur() - enableAutocomplete: -> # No need to enable anything if user is not logged in return if !gon.current_user_id @@ -287,8 +280,6 @@ class @SearchAutocomplete value: @originalState._location ) - @dropdown.removeClass 'open' - badgePresent: -> @locationBadgeEl.length |