Compare commits
2 commits
e8b653737c
...
8398670530
Author | SHA1 | Date | |
---|---|---|---|
8398670530 | |||
315d306eb4 |
3 changed files with 40 additions and 1 deletions
|
@ -56,7 +56,7 @@
|
|||
</div>
|
||||
<div class="panel-body">
|
||||
<div
|
||||
v-if="!loadedInitially"
|
||||
v-if="!Object.values(loading).includes(false) && !hasAtLeastOneResult"
|
||||
class="text-center loading-icon"
|
||||
>
|
||||
<FAIcon
|
||||
|
|
|
@ -10,6 +10,12 @@ library.add(
|
|||
)
|
||||
|
||||
const SearchBar = {
|
||||
mounted () {
|
||||
window.addEventListener('keydown', this.autoFocus)
|
||||
},
|
||||
beforeDestroy () {
|
||||
window.removeEventListener('keydown', this.autoFocus)
|
||||
},
|
||||
data: () => ({
|
||||
searchTerm: undefined,
|
||||
hidden: true,
|
||||
|
@ -36,6 +42,36 @@ const SearchBar = {
|
|||
this.$refs.searchInput.focus()
|
||||
}
|
||||
})
|
||||
},
|
||||
autoFocus (event) {
|
||||
if (
|
||||
event.target.tagName !== 'BODY' ||
|
||||
event.altKey ||
|
||||
event.ctrlKey ||
|
||||
event.isComposing ||
|
||||
event.metaKey ||
|
||||
event.repeat ||
|
||||
event.shiftKey
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.key === '/') {
|
||||
if (this.hidden) {
|
||||
this.toggleHidden()
|
||||
} else {
|
||||
this.$refs.searchInput.focus()
|
||||
}
|
||||
event.preventDefault()
|
||||
} else if (event.key === 'Escape') {
|
||||
if (!this.hidden) {
|
||||
this.toggleHidden()
|
||||
}
|
||||
event.preventDefault()
|
||||
}
|
||||
},
|
||||
blur () {
|
||||
this.$refs.searchInput.blur()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
@keydown.enter="
|
||||
$event.isComposing || $event.keyCode === 229 || find(searchTerm)
|
||||
"
|
||||
@keydown.escape="
|
||||
$event.isComposing || blur()
|
||||
"
|
||||
>
|
||||
<button
|
||||
class="button-default search-button"
|
||||
|
|
Loading…
Reference in a new issue