Added anchors for document headings

This commit is contained in:
Jori Lallo
2016-05-29 15:22:33 -07:00
parent 249c67011a
commit 4f630aadc8
5 changed files with 57 additions and 2 deletions

View File

@@ -17,6 +17,19 @@ class DocumentScene extends React.Component {
this.props.fetchDocumentAsync(documentId);
}
componentWillReceiveProps = (nextProps) => {
// Scroll to anchor after loading
const hash = this.props.location.hash;
if (nextProps.document && hash) {
const name = hash.split('#')[1];
setTimeout(() => {
const element = document.getElementsByName(name)[0];
if (element) element.scrollIntoView()
}, 0);
}
}
render() {
const document = this.props.document;
let title;