Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion dev/Dev.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div id="app">
<v-select v-model="selected" v-bind="config" />
<button v-if="config.appendToBody" @click="hide">Hide</button>
<v-select v-if="!hidden" v-model="selected" v-bind="config" />
</div>
</template>

Expand All @@ -11,11 +12,21 @@ import countries from '../docs/.vuepress/data/countryCodes.js'
export default {
components: { vSelect },
data: () => ({
hidden: false,
selected: null,
config: {
options: countries,
appendToBody: true,
},
}),
methods: {
hide() {
this.hidden = true
setTimeout(() => {
this.hidden = false
}, 2000)
},
},
}
</script>

Expand Down
98 changes: 50 additions & 48 deletions src/components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,55 +82,57 @@
</slot>
</div>
</div>
<transition :name="transition">
<ul
v-if="dropdownOpen"
:id="`vs${uid}__listbox`"
ref="dropdownMenu"
:key="`vs${uid}__listbox`"
v-append-to-body
class="vs__dropdown-menu"
role="listbox"
tabindex="-1"
@mousedown.prevent="onMousedown"
@mouseup="onMouseUp"
>
<slot name="list-header" v-bind="scope.listHeader" />
<li
v-for="(option, index) in filteredOptions"
:id="`vs${uid}__option-${index}`"
:key="getOptionKey(option)"
role="option"
class="vs__dropdown-option"
:class="{
'vs__dropdown-option--deselect':
isOptionDeselectable(option) && index === typeAheadPointer,
'vs__dropdown-option--selected': isOptionSelected(option),
'vs__dropdown-option--highlight': index === typeAheadPointer,
'vs__dropdown-option--disabled': !selectable(option),
}"
:aria-selected="index === typeAheadPointer ? true : null"
@mouseover="selectable(option) ? (typeAheadPointer = index) : null"
@click.prevent.stop="selectable(option) ? select(option) : null"
<Teleport to="body" :disabled="!appendToBody">
<transition :name="transition">
<ul
v-if="dropdownOpen"
:id="`vs${uid}__listbox`"
ref="dropdownMenu"
:key="`vs${uid}__listbox`"
v-append-to-body
class="vs__dropdown-menu"
role="listbox"
tabindex="-1"
@mousedown.prevent="onMousedown"
@mouseup="onMouseUp"
>
<slot name="option" v-bind="normalizeOptionForSlot(option)">
{{ getOptionLabel(option) }}
</slot>
</li>
<li v-if="filteredOptions.length === 0" class="vs__no-options">
<slot name="no-options" v-bind="scope.noOptions">
Sorry, no matching options.
</slot>
</li>
<slot name="list-footer" v-bind="scope.listFooter" />
</ul>
<ul
v-else
:id="`vs${uid}__listbox`"
role="listbox"
style="display: none; visibility: hidden"
></ul>
</transition>
<slot name="list-header" v-bind="scope.listHeader" />
<li
v-for="(option, index) in filteredOptions"
:id="`vs${uid}__option-${index}`"
:key="getOptionKey(option)"
role="option"
class="vs__dropdown-option"
:class="{
'vs__dropdown-option--deselect':
isOptionDeselectable(option) && index === typeAheadPointer,
'vs__dropdown-option--selected': isOptionSelected(option),
'vs__dropdown-option--highlight': index === typeAheadPointer,
'vs__dropdown-option--disabled': !selectable(option),
}"
:aria-selected="index === typeAheadPointer ? true : null"
@mouseover="selectable(option) ? (typeAheadPointer = index) : null"
@click.prevent.stop="selectable(option) ? select(option) : null"
>
<slot name="option" v-bind="normalizeOptionForSlot(option)">
{{ getOptionLabel(option) }}
</slot>
</li>
<li v-if="filteredOptions.length === 0" class="vs__no-options">
<slot name="no-options" v-bind="scope.noOptions">
Sorry, no matching options.
</slot>
</li>
<slot name="list-footer" v-bind="scope.listFooter" />
</ul>
<ul
v-else
:id="`vs${uid}__listbox`"
role="listbox"
style="display: none; visibility: hidden"
></ul>
</transition>
</Teleport>
<slot name="footer" v-bind="scope.footer" />
</div>
</template>
Expand Down
5 changes: 0 additions & 5 deletions src/directives/appendToBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default {
left: scrollX + left + 'px',
top: scrollY + top + height + 'px',
})

document.body.appendChild(el)
}
},

Expand All @@ -24,9 +22,6 @@ export default {
if (el.unbindPosition && typeof el.unbindPosition === 'function') {
el.unbindPosition()
}
if (el.parentNode) {
el.parentNode.removeChild(el)
}
}
},
}