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

Fix portal/popover position and scrolling issues #326

Merged
merged 11 commits into from
Dec 9, 2016
Merged

Conversation

cmslewis
Copy link
Contributor

@cmslewis cmslewis commented Dec 7, 2016

Fixes #231, Fixes #240

Changes proposed in this pull request:

  • Change .pt-portal to position:absolute to take it out of document flow.
    This prevents browsers from autoscrolling to the bottom of the document (where portals are appended) when programmatically .focus()'ing within a portal child element.
  • Stick .pt-portal to the top, left, and right of the body.
    This ensures that content still calculates offsets from the top of the document and that content won't be horizontally scrunched.
  • Move tabindex from the .pt-overlay wrapper down to the overlay's immediate children.
    Despite the CSS changes above, programmatically .focus()'ing on the overlay can still cause autoscrolling to the bottom of the page in some cases. Moving the tabindex to the overlay content ensures that the browser will scroll to the content itself if need be, not to some hidden parent element.
  • Upgrade Tether from v1.2.0 to v1.4.0 to pick up this crucial PR.
    This helps us solve an issue wherein Tether was removing portal content nodes and reinserting them as immediate children of the body if any ancestor was not position: static. This in turn severed React's handles on the original DOM nodes.

Reviewers should focus on:

  • Before merging this, we'll need to wait on this DefinitelyTyped PR to merge; that'll give us the type declaration for Tether's new bodyElement option.
  • We should open an issue on Tether after this, explaining why we needed such a horrible workaround with the fakeHtmlElement.
  • Testing on different browsers (I checked on Safari, Firefox, and Chrome on Mac OS X).

// thus, we pass a fake HTML bodyElement to Tether,
// with a no-op `appendChild` function (the only
// function the library uses from bodyElement.)
const fauxHtmlElement = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid using "faux" in the terminology and instead opt for a more straightforward name, fakeBodyElement. It's harder to follow for non-native English speakers. -1 for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -14,6 +14,19 @@ const DEFAULT_CONSTRAINTS = {
to: "scrollParent",
};

// per https://github.com/HubSpot/tether/pull/204,
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I think the line breaks are a little too aggressive here -- you could comfortably take up more horizontal space

Copy link
Contributor

@giladgray giladgray Dec 7, 2016

Choose a reason for hiding this comment

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

so true! at least 80 characters, could go up to 💯.

Copy link
Contributor

Choose a reason for hiding this comment

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

longer lines will make these comments look less wordy too 👒

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// take the portal out of the document flow to prevent
// browsers from autoscrolling to the bottom of the document
// (where portals are appended) when programmatically
// .focus()'ing within a portal child element. also, don't
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: don't need to say ".focus()", just use plain English, e.g. "focussing"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@adidahiya
Copy link
Contributor

If the DefinitelyTyped PR doesn't merge in the next couple days, I think you should go ahead with this PR for this week's release (but I think they're pretty quick and I already reviewed it, so you should be 👌 )

@cmslewis
Copy link
Contributor Author

cmslewis commented Dec 9, 2016

@adidahiya the DefinitelyTyped PR hasn't merged yet. How do we move ahead with this PR properly in the meantime?

@adidahiya
Copy link
Contributor

@cmslewis you should be able to merge namespaces and add the field you need

@giladgray
Copy link
Contributor

@adidahiya in which file? declaration merging can only be done in .d.ts files and we track a single one (they're all from @types). time to add a shim.d.ts for like one release?

@bbenezech
Copy link
Contributor

Chrome 55.0.2883.87 (64-bit) (Mac) looks affected as well.
I do think I had no problem with 54 yesterday, but can't be 100% sure. Is it just me?

@adidahiya
Copy link
Contributor

@giladgray yes, you can add a custom-typings.d.ts for one release.

@adidahiya adidahiya dismissed their stale review December 9, 2016 22:12

addressed comments

@blueprint-bot
Copy link

merge declarations to shim `bodyElement` prop

Preview: docs | landing | table
Coverage: core | datetime

Copy link
Contributor

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

🌮

@cmslewis
Copy link
Contributor Author

cmslewis commented Dec 9, 2016

Verified on Chrome (v55) + Firefox + Safari on OS X and IE + Chrome on Windows.

@cmslewis cmslewis merged commit 82f35f3 into master Dec 9, 2016
@cmslewis cmslewis deleted the cl/portal-position branch December 9, 2016 22:28
greglo pushed a commit to greglo/blueprint that referenced this pull request Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants