Skip to content

Commit c5b91be

Browse files
committed
respect rowHeight
1 parent 027ca10 commit c5b91be

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 1.0.1
4+
5+
### Bugfix
6+
7+
- `rowHeight` is now respected
8+
- when there is overflow-x, borders should remain
9+
310
## 1.0.0
411

512
_2024-12-12_

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fluid-table",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A React table inspired by @tanstack/react-virtual",
55
"author": "Mckervin Ceme <mckervinc@live.com>",
66
"license": "MIT",

src/components/Header.tsx

+16-12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type HeaderProps<T> = {
5858
uuid: string;
5959
columns: ColumnProps<T>[];
6060
pixelWidths: number[];
61+
showRowWrapper: boolean;
6162
className?: string;
6263
style?: React.CSSProperties;
6364
sortColumn?: string;
@@ -69,6 +70,7 @@ const Header = forwardRef(function <T>(
6970
{
7071
uuid,
7172
columns,
73+
showRowWrapper,
7274
pixelWidths,
7375
className,
7476
style,
@@ -111,18 +113,20 @@ const Header = forwardRef(function <T>(
111113

112114
return (
113115
<div ref={ref} className="rft-sticky-header" data-header-key={`${uuid}-header`}>
114-
<div className={cx("rft-header", className)} style={style}>
115-
{columns.map((c, i) => (
116-
<HeaderCell
117-
key={c.key}
118-
width={pixelWidths[i]}
119-
sortedCol={sortedCol}
120-
sortedDir={sortedDir}
121-
column={c as ColumnProps<any>}
122-
onHeaderClick={onHeaderClick as any}
123-
prevWidth={c.frozen ? pixelWidths.slice(0, i).reduce((pv, c) => pv + c, 0) : 0}
124-
/>
125-
))}
116+
<div className={cx(showRowWrapper && "rft-row-wrapper")}>
117+
<div className={cx("rft-header", className)} style={style}>
118+
{columns.map((c, i) => (
119+
<HeaderCell
120+
key={c.key}
121+
width={pixelWidths[i]}
122+
sortedCol={sortedCol}
123+
sortedDir={sortedDir}
124+
column={c as ColumnProps<any>}
125+
onHeaderClick={onHeaderClick as any}
126+
prevWidth={c.frozen ? pixelWidths.slice(0, i).reduce((pv, c) => pv + c, 0) : 0}
127+
/>
128+
))}
129+
</div>
126130
</div>
127131
</div>
128132
);

src/components/List.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, {
77
useRef,
88
useState
99
} from "react";
10+
import { useResizeDetector } from "react-resize-detector";
1011
import { ColumnProps, ScrollAlignment, TableProps, TableRef } from "../..";
1112
import { DEFAULT_ROW_HEIGHT } from "../constants";
1213
import { arraysMatch, calculateColumnWidths, cx, findColumnWidthConstants } from "../util";
@@ -61,6 +62,7 @@ const List = forwardRef(function <T>(
6162
// hooks
6263
const parentRef = useRef<HTMLDivElement | null>(null);
6364
const headerRef = useRef<HTMLDivElement | null>(null);
65+
const { ref: innerRef, width: innerWidth = 0 } = useResizeDetector<HTMLDivElement>();
6466
const [pixelWidths, setPixelWidths] = useState<number[]>([]);
6567
const [widthConstants, setWidthConstants] = useState(findColumnWidthConstants(columns));
6668
const [expandedCache, setExpandedCache] = useState<Record<string | number, boolean>>({});
@@ -76,6 +78,7 @@ const List = forwardRef(function <T>(
7678
});
7779

7880
// constants
81+
const showRowWrapper = (innerRef.current?.scrollWidth || 0) > innerWidth;
7982
const items = virtualizer.getVirtualItems();
8083
const { fixedWidth, remainingCols } = widthConstants;
8184

@@ -157,6 +160,7 @@ const List = forwardRef(function <T>(
157160
<Header
158161
ref={headerRef}
159162
uuid={uuid}
163+
showRowWrapper={showRowWrapper}
160164
pixelWidths={pixelWidths}
161165
columns={columns as ColumnProps<any>[]}
162166
className={headerClassname}
@@ -167,12 +171,13 @@ const List = forwardRef(function <T>(
167171
/>
168172
<div className="rft-outer-container" style={{ height: virtualizer.getTotalSize() }}>
169173
<div
174+
ref={innerRef}
170175
className="rft-inner-container"
171176
style={{
172177
transform: `translateY(${items[0]?.start ?? 0}px)`
173178
}}
174179
>
175-
<div className="rft-row-wrapper">
180+
<div className={cx(showRowWrapper && "rft-row-wrapper")}>
176181
{items.map(item => {
177182
const row = data[item.index];
178183
const key = generateKeyFromRow(row, item.index);
@@ -182,6 +187,8 @@ const List = forwardRef(function <T>(
182187
const style = typeof rowStyle === "function" ? rowStyle(item.index) : rowStyle;
183188
return (
184189
<Row
190+
ref={virtualizer.measureElement}
191+
rowHeight={rowHeight}
185192
key={key}
186193
row={row}
187194
uuid={uuid}
@@ -196,7 +203,6 @@ const List = forwardRef(function <T>(
196203
columns={columns as any}
197204
pixelWidths={pixelWidths}
198205
subComponent={subComponent as any}
199-
ref={virtualizer.measureElement}
200206
/>
201207
);
202208
})}

src/components/Row.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { forwardRef, memo, useCallback } from "react";
1+
import React, { forwardRef, JSX, memo, useCallback } from "react";
22
import { ColumnProps, RowRenderProps, SubComponentProps } from "../..";
33
import Minus from "../svg/minus-circle.svg";
44
import Plus from "../svg/plus-circle.svg";
5-
import { cx } from "../util";
5+
import { cx, positive } from "../util";
66

77
type TableCellProps<T> = {
88
row: T;
@@ -138,6 +138,7 @@ type RowProps<T> = {
138138
pixelWidths: number[];
139139
columns: ColumnProps<T>[];
140140
isExpanded: boolean;
141+
rowHeight?: number;
141142
onExpand: (
142143
row: T,
143144
index: number,
@@ -162,12 +163,13 @@ const Row = forwardRef(function <T>(
162163
row,
163164
rowKey,
164165
columns,
166+
rowHeight,
165167
pixelWidths,
166168
isExpanded,
167169
onExpand,
168170
onRowClick,
169171
className,
170-
style,
172+
style = {},
171173
rowRenderer,
172174
subComponent: SubComponent
173175
}: RowProps<T>,
@@ -184,7 +186,7 @@ const Row = forwardRef(function <T>(
184186
row={row}
185187
index={index}
186188
className={cx("rft-row", className)}
187-
style={style}
189+
style={{ height: positive(rowHeight) ? rowHeight : undefined, ...style }}
188190
onRowClick={onRowClick}
189191
rowRenderer={rowRenderer}
190192
>

0 commit comments

Comments
 (0)