I have a react app that uses React-Leaflet. The Application renders a map, and on top of the map there should be a component that shows a modal. Instead, the modal is shown underneath the map. How can I make the modal show on top of the map instead like it's supposed to?
Code:
export default function AssignArea() {
return (
<Container maxWidth="sm" style={{ position:"absolute", zIndex: 100 }}>
<Typography variant="h1" component="h2">
ASSIGN AREA
</Typography>
<Input placeholder="Title"></Input>
<SketchPicker />
<Input></Input>
<Button color="error" variant="text"><DeleteIcon/>CANCEL</Button>
<Button color="primary" variant="text"><RoomIcon/>CONFIRM</Button>
</Container>
);
}
return (
<MapContainer
center={[mapBase.lat, mapBase.lng]}
zoom={mapBase.zoom}
maxBounds={bounds}
style={{ height: '100vh', width: '100%', position: 'relative', zIndex: 0 }}
zoomControl={true}
attributionControl={true}
>
{/* Base map layer */}
<TileLayer
url='https://tile.openstreetmap.org/{z}/{x}/{y}.png'
maxZoom={20}
zoomOffset={-1}
tileSize={512}
zIndex={0}
/>
<RemoveUkraineFlag />
<Markers />
<Zones />
<UiBase />
<Dropdown />
{showAssignModalAtomValue ? <AssignArea /> : null}
</MapContainer>
);
The MapContainer has a lower z-Index than the AssignArea component, but it still renders under the map. How come?
zIndex, have you looked intocreatePortal?MapContainerand then useposition: fixed& higherzIndex.