Reputation: 2342
I'm using an Autocomplete
component from @react-google-maps/api package.
Here is the documentation for the Autocomplete
component.
First case:
As we can see in the screenshot below the Autocomplete
gives us some suggestions under the input
or text field
element itself.
But when I wrap the Autocomplete
and text field
components inside a Dialog
component from Material-UI, the suggestions are shown under the Dialog
component as we can see in the screenshot below.
Here is the code (note: please insert your Google Maps API key in the index.js
file)
dependencies (in package.json file):
"@material-ui/core": "^4.12.3",
"@material-ui/styles": "^4.11.4",
"@react-google-maps/api": "^2.4.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
Second case:
If we hit enter after inserting some characters to the Autocomplete
, the app will crash and print an error autocomplete.getPlaces() is not a function
My questions:
Autocomplete
appear directly under the Autocomplete
itself (not under the Dialog
component)?autocomplete.getPlaces() is not a function
?Upvotes: 4
Views: 3471
Reputation: 81400
The dropdown element that displays behind the Dialog
has a class name called pac-container
(you can see it by inspecting the element). You can set the zIndex
of it to a higher number than the Dialog
itself to force it appearing in front of the Dialog
background:
const useStyles = makeStyles((theme) => ({
dialog: {
// the dropdown is next to the dialog root, not inside
"& + .pac-container": {
zIndex: theme.zIndex.modal + 1
}
}
}));
<Dialog className={classes.dialog}
Upvotes: 4