question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sticky component not sticky

See original GitHub issue

Hey there. Maybe I’m doing something wrong, I’m not entirely sure, but it seems that, after following your basic demo code, I ain’t able to create a navigation bar that sticks to the left side of my page. This is the page as it is now (without the sticky component): image If I start scrolling down, it won’t follow the viewport, of course. However, I tried installing and recreating your example, with little to no successful results.

Instead of having my MenuButtons, MenuTrees and MenuItems directly on the return part of the render() method, I created a const that has essentially the same content (sorry for the verbose response): const navbar = ( <div> <StickyContainer style={{ zIndex: 2 }}> <Sticky> {({ isSticky, wasSticky, style, distanceFromTop, distanceFromBottom, calculatedHeight }) => { return ( <div> <MenuButton path='/profile' label='Profile' icon='user-secret' /> <MenuTree path='/dashboards' label='Dashboards' icon='tachometer' level='second'> <MenuTree path='/dashboards' label='Central Refrigeração' level='third' > <MenuItem path='/dashboards/centralRefrig/synotic' label='Synotic' /> <MenuItem path='/dashboards/centralRefrig/charts' label='Charts' /> <MenuItem path='/dashboards/centralRefrig/parameters' label='Parameters' /> </MenuTree> </MenuTree> <MenuTree path='/alarms' label='Alarmistic' icon='exclamation-triangle' level='second' > <MenuItem path='/alarms' label='Alarms' /> <MenuItem path='/alarmsHistory' label='Alarms History' /> <MenuItem path='/alarmManager' label='Alarm Manager' /> </MenuTree> <MenuTree path='/checkLists' label='Check Lists' icon='check-circle' level='second' > <MenuItem path='/checkLists' label='Check List' /> <MenuItem path='/checkListHistory' label='Check List History' /> <MenuItem path='/checkListManager' label='Check List Manager' /> </MenuTree> <MenuTree path='/userManager' label='User Manager' icon='users' level='second'> <MenuTree path='/preferences' label="User Preferences" icon='cogs' level='third'> <MenuItem path='/severities' label='Severities' /> </MenuTree> </MenuTree> <MenuTree path='/task' label='Task Manager' icon='tasks' level='second'> <MenuItem path='/createTask' label='Create Task' /> <MenuItem path='/myTasks' label='My Tasks' /> <MenuItem path='/tasksHistory' label='Tasks History' /> </MenuTree> <MenuTree path='/plant' label='Plant Manager' icon='cog' level='second'> <MenuItem path='/profile' label='Profile' /> <MenuItem path='/profileEditor' label='Editor' /> <MenuItem path='/team' label='Team' /> </MenuTree> </div> ) }} </Sticky> </StickyContainer> </div> )

Then, I simply reference this const on the return part, and wait for the results. They are as follows: image Even worse, the navbar isn’t sticky…

Do you have any idea why this happens? Thanks, Gil

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
maecapozzicommented, Mar 6, 2018

I took the liberty of reformatting your code so that it’s a bit more parseable.

const navbar = (<div>
  <StickyContainer style={{ zIndex: 2 }}>
    <Sticky> {({ isSticky, wasSticky, style, distanceFromTop, distanceFromBottom, calculatedHeight }) => {
      return (
        <div>
          <MenuButton path='/profile' label='Profile' icon='user-secret' />
          <MenuTree path='/dashboards' label='Dashboards' icon='tachometer' level='second'>
            <MenuTree path='/dashboards' label='Central Refrigeração' level='third' >
              <MenuItem path='/dashboards/centralRefrig/synotic' label='Synotic' />
              <MenuItem path='/dashboards/centralRefrig/charts' label='Charts' />
              <MenuItem path='/dashboards/centralRefrig/parameters' label='Parameters' />
            </MenuTree>
          </MenuTree>
          <MenuTree path='/alarms' label='Alarmistic' icon='exclamation-triangle' level='second' >
            <MenuItem path='/alarms' label='Alarms' /> <MenuItem path='/alarmsHistory' label='Alarms History' />
            <MenuItem path='/alarmManager' label='Alarm Manager' />
          </MenuTree>
          <MenuTree path='/checkLists' label='Check Lists' icon='check-circle' level='second' >
            <MenuItem path='/checkLists' label='Check List' />
            <MenuItem path='/checkListHistory' label='Check List History' />
            <MenuItem path='/checkListManager' label='Check List Manager' />
          </MenuTree>
          <MenuTree path='/userManager' label='User Manager' icon='users' level='second'>
            <MenuTree path='/preferences' label="User Preferences" icon='cogs' level='third'>
              <MenuItem path='/severities' label='Severities' />
            </MenuTree>
          </MenuTree>
          <MenuTree path='/task' label='Task Manager' icon='tasks' level='second'>
            <MenuItem path='/createTask' label='Create Task' />
            <MenuItem path='/myTasks' label='My Tasks' />
            <MenuItem path='/tasksHistory' label='Tasks History' />
          </MenuTree>
          <MenuTree path='/plant' label='Plant Manager' icon='cog' level='second'>
            <MenuItem path='/profile' label='Profile' />
            <MenuItem path='/profileEditor' label='Editor' />
            <MenuItem path='/team' label='Team' />
          </MenuTree>
        </div>)
    }}
    </Sticky>
  </StickyContainer>
</div>)
0reactions
vcarlcommented, Mar 12, 2018

The login doesn’t work for me, it redirects me to login. The StickyContainer must be taller that the element that it contains, and divs between the Sticky and StickyContainer can cause issues with the styles applying correctly.

I don’t think this is a bug in the library, and I don’t have a lot of extra time to help you debug each step of implementation. I’m going to close this out, if you can get a reproduction that I can access, feel free to ping me (vcarl) in Reactiflux’s #need-help channel! Chat is a better medium than issues for detailed help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS position:sticky Not Working? Try This Fix
In order for the sticky element to function correctly, it needs to have at least one of it's top , right , left...
Read more >
How to Fix Issues With CSS Position Sticky Not Working?
Learn possible reasons why CSS position sticky might not be working for you · Checking for Browser Compatibility · Checking if a Threshold...
Read more >
How does the "position: sticky;" property work?
If you are creating a component and defining the css inside the component (shadow DOM / encapsulated styles), make sure the position: sticky...
Read more >
CSS Position Sticky - How It Really Works! - Elad Shechter
Sticky Item — is the element that we defined with the position: sticky styles. The element will float when the viewport position matches...
Read more >
CSS 'position: sticky' not working? Try 'overflow
If you've ever tried sticky positioning, then you have probably wondered why CSS position: sticky is not working for your web design.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found