Display clear button only if input has a value

This commit is contained in:
Alfredo Sumaran 2016-04-06 13:55:49 -05:00
parent ee87d15cf4
commit 5f4ce722c0
2 changed files with 12 additions and 11 deletions

View File

@ -142,7 +142,7 @@ class @SearchAutocomplete
@searchInput.on 'keyup', @onSearchInputKeyUp
@searchInput.on 'click', @onSearchInputClick
@searchInput.on 'focus', @onSearchInputFocus
@clearInput.on 'click', @onRemoveLocationClick
@clearInput.on 'click', @onClearInputClick
onDocumentClick: (e) =>
if not $.contains(@dropdown[0], e.target) and @isFocused
@ -189,6 +189,8 @@ class @SearchAutocomplete
# We should display the menu only when input is not empty
@enableAutocomplete()
@wrap.toggleClass 'has-value', !!e.target.value
# Avoid falsy value to be returned
return
@ -200,9 +202,8 @@ class @SearchAutocomplete
@isFocused = true
@wrap.addClass('search-active')
onRemoveLocationClick: (e) =>
onClearInputClick: (e) =>
e.preventDefault()
@removeLocationBadge()
@searchInput.val('').focus()
onSearchInputBlur: (e) =>

View File

@ -144,16 +144,16 @@
color: $location-icon-active-color;
}
}
}
&.has-location-badge {
.search-icon {
display: none;
}
&.has-value {
.search-icon {
display: none;
}
.clear-icon {
cursor: pointer;
display: block;
}
.clear-icon {
cursor: pointer;
display: block;
}
}