Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit b36d771

Browse files
olefirenkobemyguestdmitriy
authored andcommitted
Add exposed component functions
1 parent 3370afc commit b36d771

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ Gets triggered when the autocomplete input got changed
126126
#### keypress
127127
Gets triggered when a key gets pressed
128128

129+
### Exposed component functions
130+
131+
These functions are accessible by setting "ref" on the component ([Refs documentation](https://vuejs.org/v2/guide/components.html#Child-Component-Refs)). See example below how to use these functions.
132+
133+
#### clear()
134+
135+
Call to clear the value of the user input.
136+
137+
#### focus()
138+
139+
Call focus to focus on the element
140+
141+
#### blur()
142+
143+
Call blur to blur (unfocus) the element
144+
145+
#### update(value)
146+
147+
Call to update the user input with a new value
148+
149+
129150
### Example
130151

131152
Please note that you need to provide what method will listen (`v-on:placechanged`) to an event when the address data is obtained.
@@ -136,6 +157,7 @@ Please note that you need to provide what method will listen (`v-on:placechanged
136157
<h2>Your Address</h2>
137158

138159
<vue-google-autocomplete
160+
ref="address"
139161
id="map"
140162
classname="form-control"
141163
placeholder="Please type your address"
@@ -158,6 +180,12 @@ Please note that you need to provide what method will listen (`v-on:placechanged
158180
}
159181
},
160182

183+
mounted() {
184+
// To demonstrate functionality of exposed component functions
185+
// Here we make focus on the user input
186+
this.$refs.address.focus();
187+
},
188+
161189
methods: {
162190
/**
163191
* When the location found

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-google-autocomplete",
3-
"version": "1.0.7",
3+
"version": "1.0.10",
44
"description": "Vue component to Google Places Autocomplete",
55
"main": "src/VueGoogleAutocomplete.vue",
66
"homepage": "https://github.com/olefirenko/vue-google-autocomplete",

src/VueGoogleAutocomplete.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<input
3+
ref="autocomplete"
34
type="text"
45
:class="classname"
56
:id="id"
@@ -152,6 +153,35 @@
152153
this.$emit('keypress', event);
153154
},
154155
156+
/**
157+
* Clear the input
158+
*/
159+
clear() {
160+
this.autocompleteText = ''
161+
},
162+
163+
/**
164+
* Focus the input
165+
*/
166+
focus() {
167+
this.$refs.autocomplete.focus()
168+
},
169+
170+
/**
171+
* Blur the input
172+
*/
173+
blur() {
174+
this.$refs.autocomplete.blur()
175+
},
176+
177+
/**
178+
* Update the value of the input
179+
* @param {String} value
180+
*/
181+
update (value) {
182+
this.autocompleteText = value
183+
},
184+
155185
// Bias the autocomplete object to the user's geographical location,
156186
// as supplied by the browser's 'navigator.geolocation' object.
157187
geolocate() {

0 commit comments

Comments
 (0)