@jinaan/uikit 0.1.48 → 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-table.d.ts.map +1 -1
- package/dist/index.js +462 -456
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data-table.tsx +18 -6
package/package.json
CHANGED
package/src/data-table.tsx
CHANGED
|
@@ -416,6 +416,17 @@ export function DataTable<T>({
|
|
|
416
416
|
// column steals its neighbor's width and every column shifts by one.
|
|
417
417
|
const structureKey = `${selectable ? "s" : "-"}|${rowActions ? "a" : "-"}|${renderExpanded ? "e" : "-"}|${columnKey}`;
|
|
418
418
|
const structureRef = useRef(structureKey);
|
|
419
|
+
// Column widths are measured from the rendered rows, so any data change
|
|
420
|
+
// (renamed key, new row with longer content) must invalidate the pinned
|
|
421
|
+
// widths — otherwise the stale widths truncate the new content.
|
|
422
|
+
const contentKey = useMemo(() => {
|
|
423
|
+
try {
|
|
424
|
+
return JSON.stringify(rows);
|
|
425
|
+
} catch {
|
|
426
|
+
return `rows:${rows.length}`;
|
|
427
|
+
}
|
|
428
|
+
}, [rows]);
|
|
429
|
+
const contentRef = useRef(contentKey);
|
|
419
430
|
const pinned = columnWidths.length > 0;
|
|
420
431
|
|
|
421
432
|
// Panel-scroll mode: the band stays fixed to the shell and cannot scroll
|
|
@@ -430,12 +441,13 @@ export function DataTable<T>({
|
|
|
430
441
|
useLayoutEffect(() => {
|
|
431
442
|
const table = bodyTableRef.current;
|
|
432
443
|
if (!table) return;
|
|
433
|
-
if (structureRef.current !== structureKey) {
|
|
434
|
-
// Column set changed: drop the pinned widths so the body
|
|
435
|
-
// content-sized (table-auto) and the next pass measures
|
|
436
|
-
// widths
|
|
437
|
-
//
|
|
444
|
+
if (structureRef.current !== structureKey || contentRef.current !== contentKey) {
|
|
445
|
+
// Column set or row content changed: drop the pinned widths so the body
|
|
446
|
+
// re-renders content-sized (table-auto) and the next pass measures
|
|
447
|
+
// intrinsic widths again. Without this, the effect would measure the
|
|
448
|
+
// stale colgroup's shifted layout and pin the wrong (truncating) widths.
|
|
438
449
|
structureRef.current = structureKey;
|
|
450
|
+
contentRef.current = contentKey;
|
|
439
451
|
setColumnWidths((prev) => (prev.length === 0 ? prev : []));
|
|
440
452
|
return;
|
|
441
453
|
}
|
|
@@ -479,7 +491,7 @@ export function DataTable<T>({
|
|
|
479
491
|
// widths (false) and again after re-pinning (true). Safe to measure in
|
|
480
492
|
// the pinned state because the floor reads sizer spans — intrinsic in
|
|
481
493
|
// every state — never the pinned layout itself.
|
|
482
|
-
}, [structureKey, pinned, loading, error, syncBandScroll]);
|
|
494
|
+
}, [structureKey, contentKey, pinned, loading, error, syncBandScroll]);
|
|
483
495
|
|
|
484
496
|
const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0);
|
|
485
497
|
|