@jinaan/uikit 0.1.35 → 0.1.37
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 +763 -733
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data-table.tsx +31 -2
package/package.json
CHANGED
package/src/data-table.tsx
CHANGED
|
@@ -353,6 +353,7 @@ export function DataTable<T>({
|
|
|
353
353
|
// measuring the rendered body columns and pinning the band colgroup to the
|
|
354
354
|
// same pixel widths; both tables share the surface's horizontal scroller.
|
|
355
355
|
const bodyTableRef = useRef<HTMLTableElement | null>(null);
|
|
356
|
+
const bandTableRef = useRef<HTMLTableElement | null>(null);
|
|
356
357
|
const [columnWidths, setColumnWidths] = useState<number[]>([]);
|
|
357
358
|
// Deps must be primitives: visibleColumns is a fresh array every render and
|
|
358
359
|
// would re-run this effect (and its setState) in a loop.
|
|
@@ -363,11 +364,20 @@ export function DataTable<T>({
|
|
|
363
364
|
if (!table) return;
|
|
364
365
|
const measure = () => {
|
|
365
366
|
const cells = table.tBodies[0]?.rows.item(0)?.cells;
|
|
367
|
+
// The band may be squeezed narrower than its own sort-button content by
|
|
368
|
+
// the body-measured widths; scrollWidth reports the true minimum, so it
|
|
369
|
+
// floors each column and stops titles from overflowing their neighbors.
|
|
370
|
+
const bandCells = bandTableRef.current?.querySelectorAll("thead th");
|
|
366
371
|
if (!cells || cells.length === 0) {
|
|
367
372
|
setColumnWidths((prev) => (prev.length === 0 ? prev : []));
|
|
368
373
|
return;
|
|
369
374
|
}
|
|
370
|
-
const widths = Array.from(cells, (cell) =>
|
|
375
|
+
const widths = Array.from(cells, (cell, i) =>
|
|
376
|
+
Math.max(
|
|
377
|
+
Math.round(cell.getBoundingClientRect().width),
|
|
378
|
+
Math.round(bandCells?.item(i)?.scrollWidth ?? 0),
|
|
379
|
+
),
|
|
380
|
+
);
|
|
371
381
|
// Bail out when nothing changed: a new array would re-render, and the
|
|
372
382
|
// re-render would re-run this effect, looping forever.
|
|
373
383
|
setColumnWidths((prev) =>
|
|
@@ -653,6 +663,7 @@ export function DataTable<T>({
|
|
|
653
663
|
// sr-only thead); widths are pinned to the measured body columns and
|
|
654
664
|
// hidden until the first measurement lands so columns never flash.
|
|
655
665
|
<table
|
|
666
|
+
ref={bandTableRef}
|
|
656
667
|
role="presentation"
|
|
657
668
|
className="w-full table-fixed border-collapse"
|
|
658
669
|
style={{
|
|
@@ -661,9 +672,11 @@ export function DataTable<T>({
|
|
|
661
672
|
}}
|
|
662
673
|
>
|
|
663
674
|
<colgroup>
|
|
675
|
+
{selectable && <col key="selectable" style={{ width: "2.75rem" }} />}
|
|
664
676
|
{columnWidths.map((width, i) => (
|
|
665
677
|
<col key={i} style={{ width }} />
|
|
666
678
|
))}
|
|
679
|
+
{rowActions && <col key="actions" style={{ width: "11rem" }} />}
|
|
667
680
|
</colgroup>
|
|
668
681
|
<thead>
|
|
669
682
|
<tr>
|
|
@@ -752,7 +765,23 @@ export function DataTable<T>({
|
|
|
752
765
|
action={empty?.action}
|
|
753
766
|
/>
|
|
754
767
|
) : (
|
|
755
|
-
<table
|
|
768
|
+
<table
|
|
769
|
+
ref={bodyTableRef}
|
|
770
|
+
className={cn(
|
|
771
|
+
"w-full border-collapse text-left",
|
|
772
|
+
columnWidths.length > 0 ? "table-fixed" : "table-auto",
|
|
773
|
+
)}
|
|
774
|
+
style={{ width: totalWidth > 0 ? totalWidth : undefined }}
|
|
775
|
+
>
|
|
776
|
+
{columnWidths.length > 0 && (
|
|
777
|
+
<colgroup>
|
|
778
|
+
{selectable && <col key="selectable" style={{ width: "2.75rem" }} />}
|
|
779
|
+
{columnWidths.map((width, i) => (
|
|
780
|
+
<col key={i} style={{ width }} />
|
|
781
|
+
))}
|
|
782
|
+
{rowActions && <col key="actions" style={{ width: "11rem" }} />}
|
|
783
|
+
</colgroup>
|
|
784
|
+
)}
|
|
756
785
|
{/* Semantic headers for assistive tech; the visible band is presentational. */}
|
|
757
786
|
<thead className="sr-only">
|
|
758
787
|
<tr>
|