@@ -82,10 +82,15 @@ class Docs extends Util.mixin(BindMixin) {
8282 } ;
8383 this . sectionScrollPositions = { } ;
8484 this . state = {
85- activeSection : null ,
86- pageRef : null
85+ activeSection : null
8786 } ;
8887 this . viewportHeight = 0 ;
88+
89+ this . pageRef = React . createRef ( ) ;
90+ this . nodeRefs . pageHeader = React . createRef ( ) ;
91+ navigationItems . forEach (
92+ ( { id } ) => ( this . nodeRefs . sectionRefs [ id ] = React . createRef ( ) )
93+ ) ;
8994 }
9095
9196 componentDidMount ( ) {
@@ -97,17 +102,16 @@ class Docs extends Util.mixin(BindMixin) {
97102 }
98103
99104 handleNavigationClick ( id ) {
100- const { pageRef } = this . state ;
101105 const sectionPosition = this . sectionScrollPositions [ id ] ;
102106
103- if ( pageRef && sectionPosition != null ) {
104- pageRef . scrollTop = sectionPosition ;
107+ if ( this . pageRef . current && sectionPosition != null ) {
108+ this . pageRef . current . scrollTop = sectionPosition ;
105109 }
106110 }
107111
108112 handlePageScroll ( ) {
109113 let activeSection = null ;
110- const pageScrollTop = this . state . pageRef . scrollTop ;
114+ const pageScrollTop = this . pageRef . current . scrollTop ;
111115 const scrollThreshhold = pageScrollTop + this . viewportHeight / 2 ;
112116
113117 Object . keys ( this . sectionScrollPositions ) . forEach ( ref => {
@@ -122,18 +126,13 @@ class Docs extends Util.mixin(BindMixin) {
122126 }
123127 }
124128
125- setPageRef ( pageRef ) {
126- if ( this . state . pageRef === null ) {
127- this . setState ( { pageRef } ) ;
128- }
129- }
130-
131129 calculateNodePositions ( ) {
132- const pageHeaderHeight = this . nodeRefs . pageHeader . offsetHeight ;
130+ const pageHeaderHeight = this . nodeRefs . pageHeader . current . offsetHeight ;
133131 this . viewportHeight = DOMUtil . getViewportHeight ( ) ;
134132
135133 Object . keys ( this . nodeRefs . sectionRefs ) . forEach ( ref => {
136- const top = this . nodeRefs . sectionRefs [ ref ] . offsetTop + pageHeaderHeight ;
134+ const top =
135+ this . nodeRefs . sectionRefs [ ref ] . current . offsetTop + pageHeaderHeight ;
137136 this . sectionScrollPositions [ ref ] = top ;
138137 } ) ;
139138 }
@@ -162,26 +161,20 @@ class Docs extends Util.mixin(BindMixin) {
162161
163162 render ( ) {
164163 let docsContent = null ;
165- const { pageRef } = this . state ;
166164
167165 // Delay the rendering of the components until we have a reference to the
168166 // scrolling container's DOM node.
169- if ( pageRef !== null ) {
167+ if ( this . pageRef !== null ) {
170168 docsContent = navigationItems . map ( ( navigationItem , index ) => {
171169 const { id, passScrollContainer } = navigationItem ;
172170 const props = { } ;
173171
174172 if ( passScrollContainer ) {
175- props . scrollContainer = pageRef ;
173+ props . scrollContainer = this . pageRef ;
176174 }
177175
178176 return (
179- < div
180- key = { index }
181- ref = { ref => {
182- this . nodeRefs . sectionRefs [ id ] = ref ;
183- } }
184- >
177+ < div key = { index } ref = { this . nodeRefs . sectionRefs [ id ] } >
185178 < navigationItem . component { ...props } />
186179 </ div >
187180 ) ;
@@ -206,12 +199,12 @@ class Docs extends Util.mixin(BindMixin) {
206199 className = "page flex-item-grow-1"
207200 id = "page"
208201 onScroll = { this . handlePageScroll }
209- ref = { ref => this . setPageRef ( ref ) }
202+ ref = { this . pageRef }
210203 >
211204 < div
212205 id = "page-header"
213206 className = "page-header fill fill-light left"
214- ref = { ref => ( this . nodeRefs . pageHeader = ref ) }
207+ ref = { this . nodeRefs . pageHeader }
215208 >
216209 < div id = "page-header-inner" className = "page-header-inner" >
217210 < div className = "container-fluid pod" >
0 commit comments