New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KZL 299 - Autocomplete on attribute name in basic filters #434
Changes from 43 commits
e1ac9fa
73185c8
705ac95
9062ba7
7dfe79d
a3e1110
c4c5e40
b04d4ee
c4dc0ea
95e56d2
5695aaf
2d24043
a4afe37
65e9c6f
e453291
6657c9e
44aaaf6
1c25c91
00dc00c
cd168ff
3382e05
5860e90
2f27b1f
66efa1c
1f7d308
550701e
831f2dd
83554f1
dd8363c
d397985
0723398
613743b
5c9e00b
fb31ba4
9227671
15999c4
2fe5865
a1c6f49
ee8af53
5c64ba1
73a8f31
ae24c29
dbc0217
353c205
f6f05a4
946ad6c
0d2f91d
a082285
a215a9d
8929e23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<template> | ||
<div> | ||
<input | ||
type="text" | ||
v-model="search" | ||
:class="inputClass" | ||
:placeholder="placeholder" | ||
@input="onInput" | ||
@keydown.down="onArrowDown" | ||
@keydown.up="onArrowUp" | ||
@keydown.enter.prevent="onEnter" | ||
/> | ||
|
||
<ul class="autocomplete-results" v-show="isOpen"> | ||
<li | ||
v-for="(result, i) in results" | ||
:key="i" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@click="setResult(result)" | ||
class="autocomplete-result" | ||
:class="{ 'is-active': i === arrowCounter }" | ||
> | ||
{{ result }} | ||
</li> | ||
</ul> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'autocomplete', | ||
props: { | ||
item: { | ||
type: String, | ||
required: false, | ||
default: () => '' | ||
}, | ||
items: { | ||
type: Array, | ||
required: false, | ||
default: () => [] | ||
}, | ||
inputClass: { | ||
type: String, | ||
required: false, | ||
default: () => '' | ||
}, | ||
placeholder: { | ||
type: String, | ||
required: false, | ||
default: () => '' | ||
} | ||
}, | ||
data() { | ||
return { | ||
search: '', | ||
results: [], | ||
isOpen: false, | ||
arrowCounter: -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd call this |
||
} | ||
}, | ||
methods: { | ||
onInput() { | ||
this.isOpen = true | ||
this.filterResults() | ||
}, | ||
filterResults() { | ||
this.results = this.items.filter(item => item.toLowerCase().indexOf(this.search.toLowerCase()) > -1) | ||
}, | ||
setResult(result) { | ||
this.search = result | ||
this.isOpen = false | ||
this.$emit('autocomplete::change', result) | ||
}, | ||
onArrowDown() { | ||
if (this.arrowCounter + 1 < this.results.length) { | ||
this.arrowCounter = this.arrowCounter + 1 | ||
} | ||
}, | ||
onArrowUp() { | ||
if (this.arrowCounter > 0) { | ||
this.arrowCounter = this.arrowCounter - 1 | ||
} | ||
}, | ||
onEnter() { | ||
this.setResult(this.results[this.arrowCounter]) | ||
this.arrowCounter = -1 | ||
}, | ||
handleClickOutside(evt) { | ||
if (!this.$el.contains(evt.target)) { | ||
this.isOpen = false | ||
this.arrowCounter = -1 | ||
} | ||
} | ||
}, | ||
mounted() { | ||
document.addEventListener('click', this.handleClickOutside) | ||
}, | ||
destroyed() { | ||
document.removeEventListener('click', this.handleClickOutside) | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be scoped? |
||
.autocomplete-results { | ||
padding: 0; | ||
margin: 0; | ||
border: 1px solid #eeeeee; | ||
height: 120px; | ||
overflow: auto; | ||
} | ||
|
||
.autocomplete-result.is-active { | ||
background-color: #0397ef; | ||
color: white; | ||
} | ||
|
||
.autocomplete-result { | ||
list-style: none; | ||
text-align: left; | ||
padding: 4px 2px; | ||
cursor: pointer; | ||
} | ||
|
||
.autocomplete-result:hover { | ||
background-color: #0397ef; | ||
color: white; | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:key="result"