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(Sticky|Visibility): add scroll context #1978

Merged
merged 4 commits into from
Aug 20, 2017
Merged

feat(Sticky|Visibility): add scroll context #1978

merged 4 commits into from
Aug 20, 2017

Conversation

mariolamacchia
Copy link
Contributor

Fixes #1959.

@codecov-io
Copy link

codecov-io commented Aug 17, 2017

Codecov Report

Merging #1978 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1978      +/-   ##
=========================================
+ Coverage    99.8%   99.8%   +<.01%     
=========================================
  Files         148     148              
  Lines        2568    2572       +4     
=========================================
+ Hits         2563    2567       +4     
  Misses          5       5
Impacted Files Coverage Δ
src/behaviors/Visibility/Visibility.js 100% <100%> (ø) ⬆️
src/modules/Sticky/Sticky.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4780cd...4f1980f. Read the comment docs.

@layershifter layershifter changed the title Add scroll context to Visibility and Sticky feat(Sticky|Visibility): add scroll context Aug 17, 2017
@TimNZ
Copy link

TimNZ commented Aug 17, 2017

@mariolamacchia Thanks.
If these (https://help.github.com/articles/checking-out-pull-requests-locally/) instructions work I'll pull down PR today and provide feedback.

@TimNZ
Copy link

TimNZ commented Aug 17, 2017

@mariolamacchia Seems to work as expected.

My positioning requirements can be likely be handled using the on* events and css.

Thanks for the rapid PR.

@TimNZ
Copy link

TimNZ commented Aug 17, 2017

@mariolamacchia I spoke too soon.

You didn't change the hardcoded window.* to use the scrollContext instead.
e.g.

window.innerHeight

->

this.props.scrollContext.innerHeight

Sticky sections are staying visible and stacking up as I scroll.

screen shot 2017-08-18 at 9 09 30 am

@@ -9,6 +9,9 @@ export interface VisibilityProps {
/** Primary content. */
children?: React.ReactNode;

/** Context which sticky element should stick to. */
context?: object;
Copy link
Member

@levithomason levithomason Aug 18, 2017

Choose a reason for hiding this comment

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

I'd assume the description here would match the Visibility component:

/** The scroll context visibility should use. */

@@ -66,11 +66,15 @@ export default class Sticky extends Component {

/** Whether element should be "pushed" by the viewport, attaching to the bottom of the screen when scrolling up. */
pushing: PropTypes.bool,

/** Context which sticky should attach `onscroll` events. */
Copy link
Member

Choose a reason for hiding this comment

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

nit: Let's match the style of the typings comment, no backticks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using the same descriptions from the SemanticUI docs. I'll use this one, without backticks, for both

@@ -66,11 +66,15 @@ export default class Sticky extends Component {

/** Whether element should be "pushed" by the viewport, attaching to the bottom of the screen when scrolling up. */
pushing: PropTypes.bool,

/** Context which sticky should attach `onscroll` events. */
scrollContext: PropTypes.object,
Copy link
Member

Choose a reason for hiding this comment

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

Based on the usage, looks like these should be .isRequired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as below

@@ -20,6 +20,9 @@ export default class Visibility extends Component {
/** Primary content. */
children: PropTypes.node,

/** The scroll context visibility should use. */
context: PropTypes.object,
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be .isRequired here given usage in code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a default value of window. isRequired means that the user must specify the value, right?

@levithomason
Copy link
Member

I'm curious as to the reasoning behind context for Visibility and scrollContext for Sticky. Why different names for these?

<Visibility context={div} />

<Sticky scrollContext={div} />

@mariolamacchia
Copy link
Contributor Author

@TimNZ scrollContext is only responsible for attaching the scroll event to a different element. If you want it to stick to something else, you should use context.

@mariolamacchia
Copy link
Contributor Author

mariolamacchia commented Aug 18, 2017

@levithomason I'm using the names from the SemanticUI docs, although it isn't very consistent:

  • context in Sticky = which element the Sticky should stick to
  • context in Visibility = scrollContext in Sticky = context of the scroll event

@levithomason
Copy link
Member

Thanks for the explanation @mariolamacchia, let's keep the parity for now then 👍

@levithomason levithomason merged commit e350886 into Semantic-Org:master Aug 20, 2017
@levithomason
Copy link
Member

Released in semantic-ui-react@0.71.5

@theCuriousOne
Copy link

Visibility BREAKS server side rendering!!!

@frogbandit
Copy link

frogbandit commented Aug 28, 2017

Hi @mariolamacchia, thank you for adding the context prop for the Visibility component! 👍 👍 for moving so fast on this.

However, I've tried using it and context doesn't seem to accept either a React ref or an HTML element. I took a look at the source code and it's just supposed to be a PropTypes.object. Can you give some more info on how to use it? i.e. what kind of element should be passed in.

@levithomason
Copy link
Member

@frogbandit we have a new component being added to the library to solve this issue, #1879. It is a Ref component.

Stateless functional components do not support refs, so we cannot be sure that a component passed in on context will support refs. Once we land #1879 it will include support for all props that accept DOM nodes and/or components, like context and as.

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.

7 participants