Skip to content

Commit 92d505c

Browse files
committed
Added ability to customize input using input named scoped slot
1 parent 51ecfde commit 92d505c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/components-implementation/autocomplete.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const props = {
2626
type: Boolean,
2727
default: false
2828
},
29+
// the name of the ref to obtain the input (if its a child of component in the slot)
30+
childRefName: {
31+
required: false,
32+
type: String,
33+
default: 'input'
34+
},
2935
options: {
3036
type: Object
3137
}
@@ -34,6 +40,14 @@ const props = {
3440
export default {
3541
mounted () {
3642
this.$gmapApiPromiseLazy().then(() => {
43+
var scopedInput = null
44+
if (this.$scopedSlots.input) {
45+
scopedInput = this.$scopedSlots.input()[0].context.$refs.input
46+
if (scopedInput && scopedInput.$refs) {
47+
scopedInput = scopedInput.$refs[this.childRefName || 'input']
48+
}
49+
if (scopedInput) { this.$refs.input = scopedInput }
50+
}
3751
if (this.selectFirstOnEnter) {
3852
downArrowSimulator(this.$refs.input)
3953
}

src/components/autocomplete.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<template>
2-
<input
3-
ref="input"
4-
v-bind="$attrs"
5-
v-on="$listeners"
6-
/>
2+
<span v-if="$scopedSlots['input']">
3+
<slot name="input" v-bind:attrs="$attrs" v-bind:listeners="$listeners" :ref="input"></slot>
4+
</span>
5+
<input v-else-if="!$scopedSlots['input']" ref="input" v-bind="$attrs" v-on="$listeners" />
76
</template>
87

98
<script>

0 commit comments

Comments
 (0)