瀏覽代碼

change how sizing for scrollgrid works a bit

Adam Shaw 6 年之前
父節點
當前提交
c3beff3ba2
共有 1 個文件被更改,包括 12 次插入8 次删除
  1. 12 8
      packages/core/src/scrollgrid/SimpleScrollGrid.tsx

+ 12 - 8
packages/core/src/scrollgrid/SimpleScrollGrid.tsx

@@ -27,7 +27,7 @@ export interface SimpleScrollGridSection extends SectionConfig {
 
 interface SimpleScrollGridState {
   shrinkWidth: number | null
-  forceYScrollbars: boolean
+  forceYScrollbars: boolean | null
   scrollerClientWidths: { [index: string]: number }
   scrollerClientHeights: { [index: string]: number }
   sizingId: string
@@ -41,9 +41,9 @@ export default class SimpleScrollGrid extends BaseComponent<SimpleScrollGridProp
   scrollerRefs = new RefMap<Scroller>()
   scrollerElRefs = new RefMap<HTMLElement, [ChunkConfig]>(this._handleScrollerEl.bind(this))
 
-  state = {
+  state: SimpleScrollGridState = {
     shrinkWidth: null,
-    forceYScrollbars: false,
+    forceYScrollbars: null,
     scrollerClientWidths: {},
     scrollerClientHeights: {},
     sizingId: ''
@@ -93,10 +93,14 @@ export default class SimpleScrollGrid extends BaseComponent<SimpleScrollGridProp
 
     let { state } = this
 
-    let needsYScrolling = getNeedsYScrolling(this.props, sectionConfig, chunkConfig) // TODO: do lazily
-    let overflowY: OverflowValue = state.forceYScrollbars ? 'scroll' : (needsYScrolling ? 'auto' : 'hidden')
+    let needsYScrolling = getAllowYScrolling(this.props, sectionConfig, chunkConfig) // TODO: do lazily
     let vGrow = getChunkVGrow(this.props, sectionConfig, chunkConfig)
 
+    let overflowY: OverflowValue =
+      state.forceYScrollbars === true ? 'scroll' :
+      (state.forceYScrollbars === false || !needsYScrolling) ? 'hidden' :
+      'auto'
+
     let content = renderChunkContent(sectionConfig, chunkConfig, {
       tableColGroupNode: microColGroupNode,
       tableMinWidth: '',
@@ -150,9 +154,9 @@ export default class SimpleScrollGrid extends BaseComponent<SimpleScrollGridProp
       let sizingId = guid()
       this.setState({
         sizingId,
-        shrinkWidth: // will create each chunk's <colgroup>
-          hasShrinkWidth(this.props.cols) ?
-            computeShrinkWidth(this.scrollerElRefs.getAll())
+        shrinkWidth: // will create each chunk's <colgroup>. TODO: precompute hasShrinkWidth
+          hasShrinkWidth(this.props.cols)
+            ? computeShrinkWidth(this.scrollerElRefs.getAll())
             : 0
       }, () => {
         if (sizingId === this.state.sizingId) {