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

Making the Sidebar Scrollable #906

Merged
merged 3 commits into from
Feb 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions components/sidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ export default class Sidebar extends Component {

this.state = {
fixed: false,
extraHeight: null,
availableHeight: null,
maxWidth: null
};
}

render() {
let { sectionName, pages, currentPage } = this.props;
let { fixed, extraHeight, maxWidth } = this.state;
let { fixed, availableHeight, maxWidth } = this.state;
let isGuides = sectionName === 'guides';

return (
<nav
className="sidebar"
ref={ ref => this._container = ref }
style={ fixed ? {
position: 'fixed',
top: -extraHeight,
width: maxWidth,
maxHeight: 'none'
} : null }>
style={{
position: fixed ? 'fixed' : null,
top: fixed ? 0 : null,
width: fixed ? maxWidth : null,
maxHeight: availableHeight
}}>

<div className="sidebar__inner">
<h3 className="sidebar-item__version">Version 2.2</h3>
Expand Down Expand Up @@ -81,11 +81,14 @@ export default class Sidebar extends Component {
let headerHeight = document.querySelector('header').offsetHeight;
let footerHeight = document.querySelector('footer').offsetHeight;
let distToBottom = scrollHeight - scrollY - innerHeight;
let availableSpace = innerHeight + distToBottom - footerHeight;


// Calculate the space that the footer and header are actually occupying
let headerSpace = scrollY > headerHeight ? 0 : headerHeight - scrollY;
let footerSpace = distToBottom > footerHeight ? 0 : footerHeight - distToBottom;

this.setState({
fixed: scrollY >= headerHeight && sidebarHeight < parentHeight,
extraHeight: sidebarHeight > availableSpace ? sidebarHeight - availableSpace : 0,
availableHeight: innerHeight - headerSpace - footerSpace,
maxWidth: parentWidth
});
}
Expand Down