Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit 7bf784a

Browse files
committed
Fixed positioning bug when append slot is used
1 parent 06d054c commit 7bf784a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-bootstrap-typeahead",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"private": false,
55
"description": "A typeahead/autocomplete component for Vue 2 using Bootstrap 4",
66
"keywords": [

src/components/VueBootstrapTypeahead.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<div :class="sizeClasses">
4-
<div v-if="$slots.prepend || prepend" class="input-group-prepend">
4+
<div ref="prependDiv" v-if="$slots.prepend || prepend" class="input-group-prepend">
55
<slot name="prepend">
66
<span class="input-group-text">{{ prepend }}</span>
77
</slot>
@@ -116,8 +116,17 @@ export default {
116116
methods: {
117117
resizeList(el) {
118118
const rect = el.getBoundingClientRect()
119-
// this.$refs.list.$el.style.top = rect.height + 5 + 'px'
120-
this.$refs.list.$el.style.width = rect.width + 'px'
119+
const listStyle = this.$refs.list.$el.style
120+
121+
// Set the width of the list on resize
122+
listStyle.width = rect.width + 'px'
123+
124+
// Set the margin when the prepend prop or slot is populated
125+
// (setting the "left" CSS property doesn't work)
126+
if (this.$refs.prependDiv) {
127+
const prependRect = this.$refs.prependDiv.getBoundingClientRect()
128+
listStyle.marginLeft = prependRect.width + 'px'
129+
}
121130
},
122131
123132
handleHit(evt) {

0 commit comments

Comments
 (0)