Skip to content

Commit 5a0d377

Browse files
author
Amelia Wattenberger
committed
fix: show overflowing numbers on hover
1 parent f20397c commit 5a0d377

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

src/components/cell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const Cell = React.memo(function (props: CellProps) {
5555

5656
const { cell: CellComponent } = cellInfo || {}
5757

58-
const displayValue = formattedValue || value;
58+
const displayValue = (formattedValue || value || "").toString();
5959
const isLongValue = (displayValue || '').length > 23;
6060
const stringWithLinks = React.useMemo(
6161
() => displayValue ? (
@@ -197,7 +197,7 @@ const CellInner = React.memo(function CellInner({
197197
<div
198198
className="cell__long-value"
199199
css={[
200-
tw` absolute p-4 py-2 bg-white opacity-0 z-30 border border-gray-200 shadow-md pointer-events-none`,
200+
tw` absolute p-4 py-2 bg-white opacity-0 z-30 border border-gray-200 shadow-md pointer-events-none break-all text-left`,
201201
isNearBottomEdge ? tw`bottom-0` : tw`top-0`,
202202
isNearRightEdge ? tw`right-0` : tw`left-0`,
203203
]}

src/components/cells/number.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ interface NumberCellProps {
77

88
export function NumberCell(props: NumberCellProps) {
99
return (
10-
<span tw="text-right font-mono text-sm block w-full" title={props.rawValue}>
10+
<div tw="truncate text-right font-mono text-sm block w-full" title={props.rawValue}>
1111
{
1212
Number.isFinite(props.value) ? props.value.toLocaleString()
1313
: !props.rawValue ? ""
1414
: '—'
1515
}
16-
</span>
16+
</div>
1717
);
1818
}

src/components/cells/string.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface StringCellProps {
99

1010
export function StringCell(props: StringCellProps) {
1111
return (
12-
<span
13-
tw="overflow-ellipsis block whitespace-nowrap overflow-hidden"
12+
<div
13+
tw="truncate"
1414
title={props.rawValue}
1515
dangerouslySetInnerHTML={{
1616
__html: DOMPurify.sanitize(props.formattedValue),

src/components/grid.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,15 @@ const CellWrapper = function (props: CellProps) {
650650
}
651651

652652
// @ts-ignore
653-
const type = cellTypes[name];
653+
const type = cellTypes[name]
654654
const cellData = filteredData[rowIndex] || { [name]: "" }
655655

656656
// if (!cellData) return null;
657657

658658
const value = cellData[name];
659659
const rawValue = cellData['__rawData__']?.[name];
660+
// @ts-ignore
661+
const formattedValue = cellTypeMap[type || ""]?.format?.(value, rawValue) || value;
660662

661663
let possibleValues = type === 'category' ? categoryValues[name] : [];
662664
const possibleValue = possibleValues?.find(d => d.value === value);
@@ -698,6 +700,7 @@ const CellWrapper = function (props: CellProps) {
698700
type={type}
699701
value={value}
700702
rawValue={rawValue}
703+
formattedValue={formattedValue}
701704
categoryColor={categoryColor}
702705
background={backgroundColor}
703706
style={style}
@@ -720,6 +723,7 @@ interface CellComputedProps {
720723
type: string;
721724
value: any;
722725
rawValue: any;
726+
formattedValue: any;
723727
style: StyleObject;
724728
background?: string;
725729
categoryColor?: string | TwStyle;

src/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ export const cellTypeMap = {
771771
number: {
772772
cell: NumberCell,
773773
filter: RangeFilter,
774-
format: (d: number) => d + '',
774+
format: (d: number) => d?.toLocaleString() + '',
775775
shortFormat: (d: number) =>
776776
d < 1000 && isAlmostInteger(d)
777777
? d3Format(',.0f')(d)

0 commit comments

Comments
 (0)