Skip to content

Conversation

@ajhenry
Copy link
Contributor

@ajhenry ajhenry commented Dec 20, 2022

This adds the following CSS properties as props to the Overlay prop to customize its position behavior.

position
top (modified)
left (modified)
right
bottom

I added tests and a story to demonstrate the new behavior.

Closes #2713

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.

@ajhenry ajhenry requested review from a team and langermank December 20, 2022 20:11
@changeset-bot
Copy link

changeset-bot bot commented Dec 20, 2022

🦋 Changeset detected

Latest commit: 0ef3178

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

This PR includes changesets to release 1 package
Name Type
@primer/react 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

@colebemis
Copy link
Contributor

@ajhenry Thank you for opening up this PR!

How do you feel about this prop API instead:

+ position: 'absolute' | 'fixed' (default: 'absolute')
  top?: number
  left?: number
+ right?: number (default: undefined)
+ bottom?: number (default: undefined)

If it feels a little more consistent with CSS.

@ajhenry
Copy link
Contributor Author

ajhenry commented Dec 22, 2022

@colebemis That makes a lot of sense to me!

Looking at it, it would probably make the most sense just to remove the left prop altogether as position and left|right|top|bottom will be added via the sx prop that's on the object

i.e. this is already valid today

<Overlay
  position="fixed"
  right={0}
/>

@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 5, 2023

@colebemis I can revise this PR today to make those changes and see how we like them!

@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 10, 2023

@colebemis friendly bump to see if this is what you're looking for 😄

@lesliecdubs
Copy link
Member

Hi @ajhenry, thanks for working on this! @colebemis is out of office this week.

Will it block you if he gets back to you on/around January 17 when he's back? If so, let me know and I can loop in another team member to review.

@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 11, 2023

@lesliecdubs No problem, thanks for the heads up! This isn't blocking anything so we're good

@joshblack joshblack added the 💓collab a vibrant hub of collaboration label Jan 13, 2023
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

These changes look great. That is exactly what I had in mind when I wrote my previous comment 👍

One thing before I approve and merge the PR: Can you update the docs to match your updated code?

@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 19, 2023

@colebemis Updated the docs! Let me know if I need to do anything else 🚀

@colebemis
Copy link
Contributor

This failing test looks related to these changes:

CleanShot 2023-01-20 at 11 22 45@2x

https://github.com/primer/react/actions/runs/3970131563/jobs/6805498589#step:8:606

@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 20, 2023

Taking a look now

@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 20, 2023

So this is failing because of the way we try to parse coordinates for the AutoSuggestions component.

The following calculation to determine line height is returning NaN for specific cases.

const lineHeight = isNaN(parseInt(computed.lineHeight))
? parseInt(computed.fontSize) * 1.2
: parseInt(computed.lineHeight)

When computed.fontSize is normal we fallback to computed.fontSize which can be blank. The problem with this is that parsing a blank string results in NaN.

parseInt("")
-> NaN

Should we default to 1 when fontSize is blank?

For example, when changing that util function to be the following, we no longer have a failing test

// Lineheight is either a number or the string 'normal'. In that case, fall back to a
// rough guess of 1.2 based on MDN: "Desktop browsers use a default value of roughly 1.2".
const lineHeight = isNaN(parseInt(computed.lineHeight))
  ? parseInt(computed.fontSize === '' ? '1' : computed.fontSize) * 1.2
  : parseInt(computed.lineHeight)

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Did some digging and this should fix the failing test:

diff --git a/src/drafts/InlineAutocomplete/InlineAutocomplete.tsx b/src/drafts/InlineAutocomplete/InlineAutocomplete.tsx
index d29b5e122..53e64d282 100644
--- a/src/drafts/InlineAutocomplete/InlineAutocomplete.tsx
+++ b/src/drafts/InlineAutocomplete/InlineAutocomplete.tsx
@@ -198,8 +198,8 @@ const InlineAutocomplete = ({
         inputRef={inputRef}
         onCommit={onCommit}
         onClose={onHideSuggestions}
-        top={suggestionsOffset.top}
-        left={suggestionsOffset.left}
+        top={suggestionsOffset.top || 0}
+        left={suggestionsOffset.left || 0}
         visible={suggestionsVisible}
         tabInsertsSuggestions={tabInsertsSuggestions}
       />

The NaN was probably an issue before this PR, but the previous implementation covered up the issue by doing top: ${top || 0}px`.

@ajhenry ajhenry force-pushed the ajhenry/overlay-position branch from 1bd42db to 33c4ff6 Compare January 23, 2023 22:16
@ajhenry
Copy link
Contributor Author

ajhenry commented Jan 23, 2023

I think this is ready for action @colebemis

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

🥳

@colebemis colebemis merged commit 8bd40de into primer:main Jan 23, 2023
@primer-css primer-css mentioned this pull request Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💓collab a vibrant hub of collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add position prop to Overlay to allow better fixed position rendering

4 participants