Skip to content

feat: Add height="initial" to Overlay #1287

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

Merged
merged 9 commits into from
Jun 11, 2021
Merged

Conversation

smockle
Copy link
Member

@smockle smockle commented Jun 10, 2021

Partial-fix for https://github.com/github/primer/issues/161. Specifically, this fixes the case where SelectPanel items are available initially (i.e. not asynchronously fetched).

This PR adds an "initial" value to Overlay’s height prop, which cause the component height to fit contents initially (like "auto"), then be fixed at that initial height, so that as contents change (e.g. by filtering), the container remains at the initial height (unlike, and preferred to, "auto").

Sidebar: The asynchronously-fetch case is partially-supported: A component consumer can initially (before items have been retrieved) pass height="auto" then (once items are retrieved) pass height="initial". Because heightKey is a dependency of the useEffect, the height-after-fetch can be set using this approach.

Screen recordings

Overflowing items
The following recording demonstrates that an Overlay with height="initial" initially opens shorter than its contents (which are scrollable, because they do not fit within the Overlay’s max-height), and remains at this height as contents are filtered. This is functionally identical to height="XSmall" when items overflow.
2021-06-10 17 16 22

Underflowing items
The following recording demonstrates that an Overlay with height="initial" initially opens exactly as large as its contents (which are not scrollable, because they fit within the Overlay’s max-height), and remains at this height as contents are filtered. This is superior to both height="XSmall" (which, with this few items, would undesirably include empty space underneath them when the Overlay opens) and height="auto" (which would remove empty space after filtering, undesirably varying the Overlay height).
2021-06-10 17 16 37

Merge checklist

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

@changeset-bot
Copy link

changeset-bot bot commented Jun 10, 2021

⚠️ No Changeset found

Latest commit: a67d270

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Jun 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/primer-components/55Q36wPoRwzpsCEqR25BWvcR25CW
✅ Preview: https://primer-components-git-selectpanel-height-initial-primer.vercel.app

@smockle smockle changed the title Selectpanel height initial feat: Add height="initial" to Overlay Jun 10, 2021
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.

Thanks for taking this on @smockle! I've been dreading this change and you did a fantastic job. Super simple solution and it works great!

src/Overlay.tsx Outdated
@@ -9,7 +9,7 @@ import {useCombinedRefs} from './hooks/useCombinedRefs'

type StyledOverlayProps = {
width?: keyof typeof widthMap
height?: keyof typeof heightMap
height?: string
Copy link
Member

Choose a reason for hiding this comment

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

This could be switched back now that we have initial in the map, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, that change is no longer necessary—we can realign the internal (StyledOverlayProps) and external (OverlapProps) contracts.

Incidentally, the reason isn’t because initial is included in heightMap, but rather because imperatively setting height means we are no longer passing arbitrary height values to the StyledOverlay component, so the type of height no longer needs to be widened from keyof typeof heightMap to string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in eb770c8

Copy link
Member Author

Choose a reason for hiding this comment

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

Sidebar: Do you think CSP would block the imperative approach? If so, we could restore the original approach (in eb298ad).

…d external contract; 'height' is not widened to 'string' in the former, because arbitrary pixel values are no longer passed via props.
@vercel vercel bot temporarily deployed to Preview June 10, 2021 23:59 Inactive
@vercel vercel bot temporarily deployed to Preview June 11, 2021 00:17 Inactive
@smockle smockle requested a review from dgreif June 11, 2021 00:32
@vercel vercel bot temporarily deployed to Preview June 11, 2021 00:37 Inactive
@vercel vercel bot temporarily deployed to Preview June 11, 2021 14:58 Inactive
@vercel vercel bot temporarily deployed to Preview June 11, 2021 17:28 Inactive
@smockle smockle requested a review from dgreif June 11, 2021 17:33
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 great!

@vercel vercel bot temporarily deployed to Preview June 11, 2021 19:00 Inactive
@smockle smockle merged commit 8c97f2b into main Jun 11, 2021
@smockle smockle deleted the selectpanel-height-initial branch June 11, 2021 19:18
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.

2 participants