Material-ui: Multiple Poppers on Google Maps show Only Current OnClick

Created on 23 Feb 2019  路  5Comments  路  Source: mui-org/material-ui

Hello I am trying to open one popper at the time. I am surprised there is not an example of this on the site. Right now all of them are opening onClick here is my code

  handleClick = (placement, id) => event => {
    const { currentTarget } = event;
    console.log(event)
    this.setState(state => ({
      anchorEl: currentTarget,
      open: state.placement !== placement || !state.open,
      placement,
    }));
  };

render() {
return (
<Paper>
  {surveyMapEvents && surveyMapEvents.length ? <div style={{ height: '600px', width: '100%' }}>
    <GoogleMapReact
      options={this.getMapOptions}
      bootstrapURLKeys={{ key: 'AIzaSyDVbG_3XsFZPYOenzXQ2lXYF56aVIkaya4' }}
      center={position}
      defaultZoom={15}
    >
      {surveyMapEvents.map((item, index) => (
        ( item.theme && 
          <MapMaker 
             aria-describedby={index} 
             key={index} 
             onClick={this.handleClick('top', index)}  
             background={item.theme.background} 
             color={item.theme.color} 
             lat={item.position.lat} 
             lng={item.position.lng}>
            <MapMakerText>{item.initial}</MapMakerText>
            <Popper id={index} open={open} anchorEl={anchorEl} placement={placement} transition>
              {({ TransitionProps }) => (
                <Fade {...TransitionProps} timeout={350}>
                  <Paper>
                    <DialogTitle>{item.name}</DialogTitle>
                  <DialogContent>
                    <DialogContentText><BoldText>Address:</BoldText> {item.address}</DialogContentText>
                    <DialogContentText><BoldText>Start at:</BoldText> {item.startTime}</DialogContentText>
                  </DialogContent>
                  <DialogActions>
                    <Button onClick={this.assign} color="primary">
                      Assign
                    </Button>
                    <Button onClick={this.delete} color="secondary">
                      Delete
                    </Button>
                    <Button onClick={this.details} color="default">
                      Details
                    </Button>
                  </DialogActions>
                  </Paper>
                </Fade>
              )}
            </Popper>
          </MapMaker> 

        )
      ))}
    </GoogleMapReact>
  </div> : <Loader />}
</Paper>
)
}

Here is Picture to reflect that I am always getting the same popper no matter on what Marker I click on Goggle Map
issue

question

All 5 comments

Looking at your code, it seems that you are opening all your Popiover at the same time. You should discriminate them. Please use StackOverflow for support questions like this one.

@oliviertassinari Can you provide an example please?

Instead of using a boolean open state, you can use a string, set the same of the Popover you want to open. In the render method, only open the Popover if the name of the open state matchs. If you need more guidance, use StackOverflow with the material-ui tag.

@oliviertassinari Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamzhouyi picture iamzhouyi  路  3Comments

mb-copart picture mb-copart  路  3Comments

finaiized picture finaiized  路  3Comments

chris-hinds picture chris-hinds  路  3Comments

ghost picture ghost  路  3Comments