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

Overlay and its composing components take a portalContainerName prop #1388

Merged
merged 3 commits into from
Sep 1, 2021

Conversation

jfuchs
Copy link
Contributor

@jfuchs jfuchs commented Aug 23, 2021

This change adds a portalContainerName prop to Overlay, AnchoredOverlay, DropdownMenu, SelectPanel, and ActionMenu. This allows overlays with an anchor inside a scrolling container to track with their anchor, so long as the specified portal is also inside that scrolling container.

Closes https://github.com/github/primer/issues/229.

Screenshots

Screen.Recording.2021-08-23.at.2.23.55.PM.mov

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@changeset-bot
Copy link

changeset-bot bot commented Aug 23, 2021

🦋 Changeset detected

Latest commit: f900777

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Aug 23, 2021

size-limit report 📦

Path Size
dist/browser.esm.js 48.43 KB (+0.04% 🔺)
dist/browser.umd.js 48.71 KB (+0.02% 🔺)

@colebemis
Copy link
Contributor

Could you explain why the portalContainerName prop is necessary?

@jfuchs
Copy link
Contributor Author

jfuchs commented Aug 31, 2021

Could you explain why the portalContainerName prop is necessary?

Good question! Today where our overlays are anchored to an element inside a scrolling element, the overlay does not track with that anchor.

Allowing components to specify their portal container gives us overlays rendered as a descendant of the scrolling element, so they track with their anchor.

@colebemis if this makes sense to you, I'll copy it to the description.

@colebemis
Copy link
Contributor

@jfuchs That makes sense! Can you add that to the PR description and the changeset?

Copy link
Member

@dgreif dgreif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the right approach, but I think we can simplify this quite a bit by leveraging the existing props

| onAction | (props: ItemProps) => void | `undefined` | Optional. If defined, this function will be called when a menu item is activated either by a click or a keyboard press. |
| open | boolean | `undefined` | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the `setOpen` prop. |
| setOpen | (state: boolean) => void | `undefined` | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the `open` prop. |
| portalContainerName | boolean | `undefined` | Optional. See the `portalContainerName` prop of `Overlay` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this type is wrong (in each of the docs). Should be string

Comment on lines 28 to 30
if (scrollingElementRef.current && includePortal) {
registerPortalRoot(scrollingElementRef.current)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This story doesn't appear to use portalContainerName. Instead, it looks like it just registers the default portal within the scrolling element

Comment on lines 172 to 171
{...(portalContainerName ? {portalContainerName} : {})}
{...overlayProps}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have an option to pass any overlayProps through the Anchored Overlays, which seems like an OK path for this option as well. It should be rarely used, kind of like height/width which use this other approach. Should significantly cut down on the surface area of this PR as well

Copy link
Member

@dgreif dgreif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much cleaner, thanks for simplifying and updating the stories! One small item then this should be good to go

src/Overlay.tsx Outdated
@@ -15,6 +15,7 @@ type StyledOverlayProps = {
maxHeight?: keyof Omit<typeof heightMap, 'auto' | 'initial'>
visibility?: 'visible' | 'hidden'
anchorSide?: AnchorSide
portalContainerName?: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only need to define this prop in OverlayProps. The values here are specifically for what gets passed in to the styled component. You should be able to remove this line without issues

@jfuchs jfuchs force-pushed the jfuchs-overlay-scrolling-explorations branch from 6a780c7 to 37e7b7a Compare September 1, 2021 17:09
@dgreif dgreif merged commit 83b888f into main Sep 1, 2021
@dgreif dgreif deleted the jfuchs-overlay-scrolling-explorations branch September 1, 2021 19:44
@primer-css primer-css mentioned this pull request Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants