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.

Inline height not recalculated on resize

See original GitHub issue

React-headroom seems to force an inline style height on the headroom-wrapper even though disableInlineStyles is set to true. I’d be fine with this if the height would recalculate when resizing, but it doesn’t.

The official version of headroom doesn’t seem to do this on the demo site.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
rafaelderolezcommented, Feb 8, 2017

After some more testing I see that headroom-wrapper gets an inline height to prevent the content underneath from jumping while switching from unfixed to unpinned.

Regardless, it would be nice if headroom recalculated its height.

2reactions
rafaelderolezcommented, Mar 14, 2017

@rusi Here’s my temporary fix:

When resizing the window, I execute setHeaderHeight which gets the height of my actual header element. I put it in the state of my component and then pass that in Headroom’s wrapperStyle prop. Hope that works for you! (You can probably debounce this to improve performance, but here’s a very barebones version.)

Note: I use disableInlineStyles as I have my own transitions and styling for Headroom.

componentDidMount() {
  this.setHeaderHeight.bind(this);
  window.addEventListener('resize', this.setHeaderHeight.bind(this));
}

setHeaderHeight() {
  const headerHeight = this.header.clientHeight;
  this.setState({ headerHeight });
}

render() {
    const { headerHeight } = this.state;

    return (
      <Headroom
        disableInlineStyles
        wrapperStyle={headerHeight}
      >
        <header ref={(ref) => { this.header = ref; }}>
        …
        </header>
      </Headroom>
  );
}

@KyleAMathews What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making Height Recalculate on Resize [closed] - Stack Overflow
Everything works as I want, except, I've been trying to get this height to recalculate and apply to <li> and <a> on window...
Read more >
line-height - CSS: Cascading Style Sheets - MDN Web Docs
The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text.
Read more >
Text box resizing behavior in Figma
When creating text boxes in Figma, there are three main resizing modes that can ... In code, the height of the headline will...
Read more >
Resizing an SVG When the Window is Resized in d3.js - Chartio
The browser doesn't inherently associate a width or height with an SVG unless ... an image, is that SVG is in fact not...
Read more >
Implement responsive aspect ratio on window resize ... - Daily.co
So far, though, the height only gets set on resize— not on load— which ... It will set the calculated height when the...
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