I was wondering if it’s possible to add a custom item into a GooglePlacesAutocomplete? I can’t seem to get it to work. Addresses work wonderfully, but I can’t add my own item, preferably to be the first item.
Tried a few things such as:
autocompletionRequest={{
componentRestrictions: { country: 'AU' },
types: ['(regions)', **'Remote'],**
}}
I also tried adding ‘option’, but had no luck. Has anyone ever done this? I need to add a default entry, specifically ‘Remote’ as I’m building a website which could have remote as a location option.
<GooglePlacesAutocomplete
apiKey="xxx"
fetchDetails={true}
defaultValue={where ? { label: where } : null}
onLoadFailed={(error) => console.error("Google Places Autocomplete load failed", error)}
selectProps={{
placeholder: "Enter suburb for the task...",
sClearable: true,
menuPortalTarget: document.body,
value: where ? { label: where } : null,
onChange: (selectedOption) => {
if (selectedOption) {
setWhere(selectedOption.label);
} else {
setWhere('');
}
},
styles: {
control: (provided) => ({
...provided,
height: '48px', // Slightly smaller to match NextUI "lg" more closely
minHeight: '48px',
borderRadius: '0.375rem', // Matches NextUI's rounded-lg
borderColor: 'hsl(214, 100%, 50%)', // Primary color similar to NextUI
boxShadow: 'none',
'&:hover': {
borderColor: 'hsl(214, 100%, 50%)',
},
'&.is-focused': {
borderColor: 'hsl(214, 100%, 50%)',
boxShadow: '0 0 0 2px rgba(0, 111, 238, 0.2)', // Similar to NextUI focus effect
},
}),
singleValue: (provided) => ({
...provided,
color: 'black',
}),
input: (provided) => ({
...provided,
color: 'black',
}),
menu: (provided) => ({
...provided,
zIndex: 9999,
borderRadius: '0.375rem',
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
}),
option: (provided, state) => ({
...provided,
backgroundColor: state.isSelected
? 'hsl(214, 100%, 50%)'
: state.isFocused
? 'hsl(214, 100%, 95%)'
: 'white',
color: state.isSelected ? 'white' : 'black',
':active': {
backgroundColor: 'hsl(214, 100%, 50%)',
color: 'white',
},
}),
dropdownIndicator: (provided) => ({
...provided,
color: 'hsl(214, 20%, 50%)', // Subtle indicator color
}),
clearIndicator: (provided) => ({
...provided,
color: 'hsl(214, 20%, 50%)', // Subtle clear indicator color
}),
},
}}
autocompletionRequest={{
componentRestrictions: { country: 'AU' },
types: ['(regions)'],
// Add a custom filter to remove train stations and other irrelevant results
strictbounds: true,
}}
/>