Bläddra i källkod

fix initial scroll for timegrid

Adam Shaw 6 år sedan
förälder
incheckning
49527e8be8

+ 6 - 0
packages/core/src/scrollgrid/SimpleScrollGrid.tsx

@@ -15,6 +15,7 @@ export interface SimpleScrollGridProps {
   vGrow?: boolean
   forPrint?: boolean
   height?: CssDimValue // TODO: give to real ScrollGrid
+  onSized?: () => void
 }
 
 export interface SimpleScrollGridSection extends SectionConfig {
@@ -197,6 +198,11 @@ export default class SimpleScrollGrid extends BaseComponent<SimpleScrollGridProp
         scrollerClientWidths: computeScrollerClientWidths(this.scrollerElRefs),
         scrollerClientHeights: computeScrollerClientHeights(this.scrollerElRefs)
       })
+
+    } else {
+      if (this.props.onSized) {
+        this.props.onSized()
+      }
     }
   }
 

+ 11 - 1
packages/timegrid/src/TimeColsView.tsx

@@ -33,6 +33,7 @@ export default abstract class TimeColsView extends View {
   private dividerElRef = createRef<HTMLTableCellElement>()
   private scrollerElRef = createRef<HTMLDivElement>()
   private axisWidth: any // the width of the time axis running down the side
+  private needsInitialScroll = false
 
 
   // abstract requirements
@@ -100,6 +101,7 @@ export default abstract class TimeColsView extends View {
           vGrow={!props.isHeightAuto}
           cols={[ { width: 'shrink' } ]}
           sections={sections}
+          onSized={this.handleGridSized}
         />
       </div>
     )
@@ -114,12 +116,20 @@ export default abstract class TimeColsView extends View {
       allDayTable.table.bottomCoordPadding = dividerEl.getBoundingClientRect().height
     }
 
-    this.scrollToInitialTime()
+    this.needsInitialScroll = true
   }
 
 
   componentDidUpdate(prevProps: ViewProps) {
     if (prevProps.dateProfile !== this.props.dateProfile) {
+      this.needsInitialScroll = true
+    }
+  }
+
+
+  handleGridSized = () => {
+    if (this.needsInitialScroll) {
+      this.needsInitialScroll = false
       this.scrollToInitialTime()
     }
   }