Autocomplete

Storybook

Open the Autocomplete story

The Autocomplete component creates a Google Places autocomplete input.

Props

PropTypeDefaultDescription
optionsgoogle.maps.places.AutocompleteOptionsAutocomplete options.
valuestring''Input value.
placeholderstringInput placeholder.
inputIdstringInput id.
inputClassstring''Input class.
classNamestring''Class alias added to the input.
inputStylestring''Input inline style.
disabledbooleanfalseDisables the input.
boundsgoogle.maps.LatLngBounds | google.maps.LatLngBoundsLiteralResult bias bounds.
componentRestrictionsgoogle.maps.places.ComponentRestrictionsComponent restrictions.
restrictionsgoogle.maps.places.ComponentRestrictionsAlias for component restrictions.
fieldsstring[]Place fields to return.
strictBoundsbooleanRestricts predictions to the bounds.
typesstring[]Place types.
onPlaceChanged() => voidPlace changed callback alias.
onLoad(autocomplete: google.maps.places.Autocomplete) => voidCalled after creation.
onUnmount(autocomplete: google.maps.places.Autocomplete) => voidCalled before teardown.

Events

The component dispatches place_changed with the selected google.maps.places.PlaceResult.

Usage

<APIProvider apiKey="YOUR_API_KEY" libraries={['places']}>
	<Autocomplete
		placeholder="Enter a location"
		fields={['name', 'geometry.location']}
		inputStyle="width: 300px; padding: 8px;"
		on:place_changed={(event) => {
			selectedPlace = event.detail;
		}}
	/>
</APIProvider>
svelte

Notes

  • Requires libraries={['places']} on APIProvider.
  • Specify fields to request only the data you need.