Skip to content

Commit ea13767

Browse files
committed
fix: sizing fix
1 parent d7b4158 commit ea13767

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

frontend/src/components/BCDataGrid/BCGridEditor.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const BCGridEditor = ({
7676
const [showRequiredIndicator, setShowRequiredIndicator] = useState(false)
7777
const [containerWidth, setContainerWidth] = useState(null)
7878
const minWidthRelaxedRef = useRef(false)
79+
const [minWidthRelaxed, setMinWidthRelaxed] = useState(false)
7980

8081
useEffect(() => {
8182
if (!showRequiredIndicator && columnDefs?.length) {
@@ -102,20 +103,30 @@ export const BCGridEditor = ({
102103
if (!columnDefs) return columnDefs
103104

104105
if (shouldFitColumns) {
105-
return addFlexToColumns(columnDefs).columnDefs
106+
const flexDefs = addFlexToColumns(columnDefs).columnDefs
107+
if (!minWidthRelaxed) {
108+
return flexDefs
109+
}
110+
return flexDefs.map((col) => ({
111+
...col,
112+
minWidth: 50
113+
}))
106114
}
107115

108116
return columnDefs.map((col) => {
109117
const nextCol = { ...col }
110118
if (nextCol.flex != null) {
111119
delete nextCol.flex
112120
}
113-
if (nextCol.minWidth && !nextCol.width) {
121+
if (!minWidthRelaxed && nextCol.minWidth && !nextCol.width) {
114122
nextCol.width = nextCol.minWidth
115123
}
124+
if (minWidthRelaxed) {
125+
nextCol.minWidth = 50
126+
}
116127
return nextCol
117128
})
118-
}, [columnDefs, shouldFitColumns])
129+
}, [columnDefs, shouldFitColumns, minWidthRelaxed])
119130

120131
// Compute defaultMinWidth from columnDefs so autoSizeStrategy uses proper initial widths
121132
// This prevents the "squished then expand" visual effect on page load
@@ -152,6 +163,7 @@ export const BCGridEditor = ({
152163
if (minWidthRelaxedRef.current) return
153164
relaxColumnMinWidths(params.api, params.columnApi, 50)
154165
minWidthRelaxedRef.current = true
166+
setMinWidthRelaxed(true)
155167
})
156168

157169
props.onGridReady?.(params)
@@ -167,6 +179,7 @@ export const BCGridEditor = ({
167179
if (minWidthRelaxedRef.current) return
168180
relaxColumnMinWidths(params.api, params.columnApi, 50)
169181
minWidthRelaxedRef.current = true
182+
setMinWidthRelaxed(true)
170183

171184
props.onFirstDataRendered?.(params)
172185
},

frontend/src/components/BCDataGrid/BCGridEditorPaginated.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export const BCGridEditorPaginated = ({
162162
const syncingFromCustomRef = useRef(false)
163163
const [scrollContentWidth, setScrollContentWidth] = useState(null)
164164
const minWidthRelaxedRef = useRef(false)
165+
const [minWidthRelaxed, setMinWidthRelaxed] = useState(false)
165166

166167
const hasInitializedFromCache = useRef(false)
167168
const previousGridKey = useRef(gridKey)
@@ -215,20 +216,30 @@ export const BCGridEditorPaginated = ({
215216
if (!columnDefs) return columnDefs
216217

217218
if (shouldFitColumns) {
218-
return addFlexToColumns(columnDefs).columnDefs
219+
const flexDefs = addFlexToColumns(columnDefs).columnDefs
220+
if (!minWidthRelaxed) {
221+
return flexDefs
222+
}
223+
return flexDefs.map((col) => ({
224+
...col,
225+
minWidth: 50
226+
}))
219227
}
220228

221229
return columnDefs.map((col) => {
222230
const nextCol = { ...col }
223231
if (nextCol.flex != null) {
224232
delete nextCol.flex
225233
}
226-
if (nextCol.minWidth && !nextCol.width) {
234+
if (!minWidthRelaxed && nextCol.minWidth && !nextCol.width) {
227235
nextCol.width = nextCol.minWidth
228236
}
237+
if (minWidthRelaxed) {
238+
nextCol.minWidth = 50
239+
}
229240
return nextCol
230241
})
231-
}, [columnDefs, shouldFitColumns])
242+
}, [columnDefs, shouldFitColumns, minWidthRelaxed])
232243

233244
// Compute defaultMinWidth from columnDefs so autoSizeStrategy uses proper initial widths
234245
// This prevents the "squished then expand" visual effect on page load
@@ -257,6 +268,7 @@ export const BCGridEditorPaginated = ({
257268
if (minWidthRelaxedRef.current) return
258269
relaxColumnMinWidths(params.api, params.columnApi, 50)
259270
minWidthRelaxedRef.current = true
271+
setMinWidthRelaxed(true)
260272

261273
props.onFirstDataRendered?.(params)
262274
},
@@ -563,6 +575,7 @@ export const BCGridEditorPaginated = ({
563575
if (minWidthRelaxedRef.current) return
564576
relaxColumnMinWidths(params.api, params.columnApi, 50)
565577
minWidthRelaxedRef.current = true
578+
setMinWidthRelaxed(true)
566579
})
567580

568581
props.onGridReady?.(params)

frontend/src/components/BCDataGrid/BCGridViewer.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export const BCGridViewer = forwardRef(
114114
const [showScrollbar, setShowScrollbar] = useState(false)
115115
const [containerWidth, setContainerWidth] = useState(null)
116116
const minWidthRelaxedRef = useRef(false)
117+
const [minWidthRelaxed, setMinWidthRelaxed] = useState(false)
117118
const syncingFromGridRef = useRef(false)
118119
const syncingFromCustomRef = useRef(false)
119120
const [scrollContentWidth, setScrollContentWidth] = useState(null)
@@ -463,6 +464,7 @@ export const BCGridViewer = forwardRef(
463464
if (minWidthRelaxedRef.current) return
464465
relaxColumnMinWidths(params.api, params.columnApi, 50)
465466
minWidthRelaxedRef.current = true
467+
setMinWidthRelaxed(true)
466468
})
467469
},
468470
[
@@ -482,6 +484,7 @@ export const BCGridViewer = forwardRef(
482484
if (minWidthRelaxedRef.current) return
483485
relaxColumnMinWidths(params.api, params.columnApi, 50)
484486
minWidthRelaxedRef.current = true
487+
setMinWidthRelaxed(true)
485488
}, [])
486489

487490
const handleChangePage = (_, newPage) => {
@@ -602,20 +605,30 @@ export const BCGridViewer = forwardRef(
602605
if (!columnDefs) return columnDefs
603606

604607
if (shouldFitColumns) {
605-
return addFlexToColumns(columnDefs).columnDefs
608+
const flexDefs = addFlexToColumns(columnDefs).columnDefs
609+
if (!minWidthRelaxed) {
610+
return flexDefs
611+
}
612+
return flexDefs.map((col) => ({
613+
...col,
614+
minWidth: 50
615+
}))
606616
}
607617

608618
return columnDefs.map((col) => {
609619
const nextCol = { ...col }
610620
if (nextCol.flex != null) {
611621
delete nextCol.flex
612622
}
613-
if (nextCol.minWidth && !nextCol.width) {
623+
if (!minWidthRelaxed && nextCol.minWidth && !nextCol.width) {
614624
nextCol.width = nextCol.minWidth
615625
}
626+
if (minWidthRelaxed) {
627+
nextCol.minWidth = 50
628+
}
616629
return nextCol
617630
})
618-
}, [columnDefs, shouldFitColumns])
631+
}, [columnDefs, shouldFitColumns, minWidthRelaxed])
619632

620633
// Compute defaultMinWidth from columnDefs so autoSizeStrategy uses proper initial widths
621634
// This prevents the "squished then expand" visual effect on page load

0 commit comments

Comments
 (0)