feat(filter): make the autocomplete look pretty
This commit is contained in:
parent
7fc1f27ef5
commit
9ade917ac4
@ -12,7 +12,6 @@ type state = 'unfocused' | 'focused'
|
|||||||
const selectedIndex = ref(-1)
|
const selectedIndex = ref(-1)
|
||||||
const state = ref<state>('unfocused')
|
const state = ref<state>('unfocused')
|
||||||
const val = ref<string>('')
|
const val = ref<string>('')
|
||||||
const isResizing = ref(false)
|
|
||||||
const model = defineModel<string>()
|
const model = defineModel<string>()
|
||||||
|
|
||||||
const suggestionScrollerRef = ref<HTMLInputElement | null>(null)
|
const suggestionScrollerRef = ref<HTMLInputElement | null>(null)
|
||||||
@ -77,38 +76,10 @@ function updateSuggestionScroll() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateScrollWindowSize() {
|
|
||||||
if (isResizing.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isResizing.value = true
|
|
||||||
|
|
||||||
nextTick(() => {
|
|
||||||
isResizing.value = false
|
|
||||||
|
|
||||||
const scroller = suggestionScrollerRef.value
|
|
||||||
const parent = containerRef.value
|
|
||||||
if (scroller) {
|
|
||||||
const rect = parent.getBoundingClientRect()
|
|
||||||
const pxTop = rect.top
|
|
||||||
const pxBottom = window.innerHeight - rect.bottom
|
|
||||||
const maxHeight = Math.max(pxTop, pxBottom, props.maxHeight)
|
|
||||||
const isReversed = pxBottom < props.maxHeight && pxTop > pxBottom
|
|
||||||
scroller.style.maxHeight = Math.min(isReversed ? pxTop : pxBottom, props.maxHeight) + 'px'
|
|
||||||
scroller.parentNode.style.transform =
|
|
||||||
isReversed ? 'translateY(-100%) translateY(-1.4rem)'
|
|
||||||
: 'translateY(.4rem)'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function setState(stateName: state) {
|
function setState(stateName: state) {
|
||||||
state.value = stateName
|
state.value = stateName
|
||||||
if (stateName === 'unfocused') {
|
if (stateName === 'unfocused') {
|
||||||
emit('blur')
|
emit('blur')
|
||||||
} else {
|
|
||||||
updateScrollWindowSize()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,3 +206,53 @@ function onUpdateField(e) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.autocomplete {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.suggestion-list {
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
background: var(--white);
|
||||||
|
border-radius: 0 0 var(--input-radius) var(--input-radius);
|
||||||
|
border: 1px solid var(--primary);
|
||||||
|
border-top: none;
|
||||||
|
|
||||||
|
max-height: 50vh;
|
||||||
|
overflow-x: auto;
|
||||||
|
z-index: 100;
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
margin-top: -2px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
|
||||||
|
font-size: .9rem;
|
||||||
|
width: 100%;
|
||||||
|
color: var(--grey-800);
|
||||||
|
text-align: left;
|
||||||
|
box-shadow: none;
|
||||||
|
text-transform: none;
|
||||||
|
font-family: $family-sans-serif;
|
||||||
|
font-weight: normal;
|
||||||
|
padding: .5rem .75rem;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:focus,
|
||||||
|
&:hover {
|
||||||
|
background: var(--grey-100);
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: var(--grey-100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@ -240,6 +240,7 @@ const autocompleteResults = ref<any[]>([])
|
|||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
v-model="filterQuery"
|
v-model="filterQuery"
|
||||||
class="input"
|
class="input"
|
||||||
|
:class="{'has-autocomplete-results': autocompleteResults.length > 0}"
|
||||||
ref="filterInput"
|
ref="filterInput"
|
||||||
></textarea>
|
></textarea>
|
||||||
<div
|
<div
|
||||||
@ -258,7 +259,7 @@ const autocompleteResults = ref<any[]>([])
|
|||||||
<template
|
<template
|
||||||
v-slot:result="{ item }"
|
v-slot:result="{ item }"
|
||||||
>
|
>
|
||||||
whoo {{ item }}
|
{{ item }}
|
||||||
</template>
|
</template>
|
||||||
</AutocompleteDropdown>
|
</AutocompleteDropdown>
|
||||||
</div>
|
</div>
|
||||||
@ -323,6 +324,10 @@ const autocompleteResults = ref<any[]>([])
|
|||||||
-webkit-text-fill-color: transparent;
|
-webkit-text-fill-color: transparent;
|
||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
resize: none;
|
resize: none;
|
||||||
|
|
||||||
|
&.has-autocomplete-results {
|
||||||
|
border-radius: var(--input-radius) var(--input-radius) 0 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter-input-highlight {
|
.filter-input-highlight {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user