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

Sticky only when custom target is out of viewport #550

Open
LeComptoirDesPharmacies opened this issue Aug 9, 2021 · 0 comments
Open

Sticky only when custom target is out of viewport #550

LeComptoirDesPharmacies opened this issue Aug 9, 2021 · 0 comments

Comments

@LeComptoirDesPharmacies
Copy link

Hi everyone,

Context :
We have a header on two rows :
First => Menu
Second => Search bar

"Search bar" (Second row) should always be sticky but "Menu" (First row) should only be sticky if user scroll back some pixels.
We successfully hide/display the "Menu" (First row) according to scroll back status.

However, we would like the full header to become sticky only when "Search bar" (Second row) is out of viewport.
At the moment, the header become sticky when any children of the component is out of viewport.

Question :
Is there any way to say "Sticky" which component it should listen position on ?

For example :

<Sticky target={customRef}>
     <ThisContentIsOptional />
     <ThisContentShouldSticky ref={customRef} />
</Sticky>

Note :
We tried to nest Sticky components in order to listen "STATUS" event of children and enable/disable parent Sticky but as soon as "Sticky" is not enabled, "onStateChange" is never called.

Ex :

<Sticky enabled={childrenSticky}>
     <ThisContentIsOptional />
     <Sticky 
         enabled={false}
         onStateChange={status => {
                if (status.status === Sticky.STATUS_FIXED) {
                  setChildrenSticky(true);
                } else {
                  setChildrenSticky(false);
                }
              }}
     >
       <ThisContentShouldSticky />
     </Sticky>
</Sticky>

Thansk in advance for your help.
Yours faithfully,
LCDP

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

No branches or pull requests

0 participants