Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add support for InfoWindow headerContent / headerDisabled options #378

Closed
usefulthink opened this issue May 21, 2024 · 11 comments · Fixed by #396 or #395 · May be fixed by AyushiSharma1234/FXNM#3 or AyushiSharma1234/FXNM#5
Closed

[Feat] Add support for InfoWindow headerContent / headerDisabled options #378

usefulthink opened this issue May 21, 2024 · 11 comments · Fixed by #396 or #395 · May be fixed by AyushiSharma1234/FXNM#3 or AyushiSharma1234/FXNM#5

Comments

@usefulthink
Copy link
Collaborator

Target Use Case

Currently in beta in the Maps JavaScript API, there will be new options for the InfoWindow, finally allowing users to disable the header including the close-button and to specify separate html for the header of the infowindow. These should be supported here as well.

Proposal

Add new props headerContent and headerDisabled for the InfoWindow component. While headerDisabled is just a boolean, headerContent can be arbitrary html, so we should support that via a render-callback, rendering the content into a portal.

@amanusovich
Copy link

amanusovich commented May 28, 2024

Hi,

I noticed this feature is already affecting the components provided here.

Screenshot 2024-05-28 at 1 03 00 PM

This is affecting the styling of the component, specially when its content is short. Providing this functionality would really help.

Thank you!

@usefulthink
Copy link
Collaborator Author

Currently this only happens with the beta version of the maps API, so we still have a bit of time..

@amanusovich
Copy link

Actually I am working with the API in the weekly version. I changed it to monthly to get the older version.

Thanks!

@usefulthink
Copy link
Collaborator Author

This already made it to weekly?
Thanks for pointing this out, that indeed changes the priority a bit :)

@chrissygonzalez
Copy link

Hello! I'd also like to vote for a little customization. 🙏 Thanks!

Screenshot 2024-05-29 at 1 22 29 PM

@kamaladenalhomsi
Copy link

Same here!! I think this is extremely important!
Not related to the issue, I want to thank the maintainers of this awesome library! Thank you for your hard work.

@kamaladenalhomsi
Copy link

For anyone facing this, you can temporary fix the empty space at the top using css:

.gm-style-iw-chr {
  position: absolute;
  display: flex;
  top: 0;
  right: 0;
}

.gm-style-iw.gm-style-iw-c {
  padding-top: 14px !important;
}

@usefulthink
Copy link
Collaborator Author

The headerDisabled flag should actually work out of the box since it should get passed on to the google.maps.InfoWindow constructor and the infowindow.setOptions() method. When using typescript you'll have to have the latest @types/google.maps installed.

As for headerContent, which API-style would be preferrable?

Option 1: Render callback ({headerContent: React.ComponentType})

<InfoWindow headerContent={() => <h3>InfoWindow Headline</h3>}></InfoWindow>
<InfoWindow headerContent={() => <>Just some text</>}></InfoWindow>

<InfoWindow headerContent={MyInfoWindowHeader}></InfoWindow>

Option 2: JSX ({headerContent: React.ReactNode})

<InfoWindow headerContent={<h3>InfoWindow Headline</h3>}></InfoWindow>
<InfoWindow headerContent={<MyInfoWindowHeader />}></InfoWindow>

Option 3: Special Child Component

<InfoWindow>
  <InfoWindowHeader><h3>InfoWindow Headline</h3></InfoWindowHeader>
  
  <p>Infowindow Content</p>
</InfoWindow>

I think I would prefer the second or third option for this. The second option seems to be what other UI libraries are using in similar situations, any opinions here?

@chrissygonzalez
Copy link

I like option 2, given that headerDisabled will be available. (At first I though option 3 was more intuitive, but you could end up in an odd situation if you set headerDisabled={true} and then also provided some header content.)

@usefulthink
Copy link
Collaborator Author

I'm mostly sceptical about option 3 since that would involve some sort of accessing portals within (or out of?) portals, and I have no Idea if that causes problems, but It's complicated to just think about. I'd be willing to figure it out if majority says that's the better solution, but we'll see...

usefulthink added a commit to usefulthink/react-google-maps that referenced this issue Jun 2, 2024
Starting with the current beta-version, the Maps API will add new options to control content and visibility of the InfoWindow-header.

This adds a new headerContent prop that renders JSX content into the InfoWindows header.

fixes visgl#378
usefulthink added a commit to usefulthink/react-google-maps that referenced this issue Jun 2, 2024
Starting with the current beta-version, the Maps API will add new options to control content and visibility of the InfoWindow-header.

This adds a new headerContent prop that renders JSX content into the InfoWindows header.

fixes visgl#378
usefulthink added a commit that referenced this issue Jun 2, 2024
Starting with the current beta-version, the Maps API will add new options to control content and visibility of the InfoWindow-header.

This adds a new headerContent prop that renders JSX content into the InfoWindows header.

fixes #378
@skulas
Copy link

skulas commented Aug 13, 2024

This is what I did, based on messages above in this thread:
const infoWnd = new google.maps.InfoWindow({ content: infoWindowContent, maxWidth:200, }) infoWnd.setHeaderDisabled(true)
and it fixed my pop-up window.
Thank you.
Wish the world learnt from swr engs how to collaborate...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment