Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit bb13bb4

Browse files
authored
Merge pull request #553 from trey-wallis/fix-number-input
Fix number input
2 parents e486982 + 766872b commit bb13bb4

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/react/table-app/currency-cell-edit/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22

33
import { useCompare, useInputSelection } from "src/shared/hooks";
4-
import { isValidNumberInput } from "src/shared/validators";
4+
import { isNumber, isValidNumberInput } from "src/shared/validators";
55
import { MenuCloseRequest } from "src/shared/menu/types";
66
import { numberInputStyle } from "src/react/table-app/shared-styles";
77

@@ -18,7 +18,8 @@ export default function CurrencyCellEdit({
1818
onChange,
1919
onMenuClose,
2020
}: Props) {
21-
const [localValue, setLocalValue] = React.useState(value);
21+
const initialValue = isNumber(value) ? value : "";
22+
const [localValue, setLocalValue] = React.useState(initialValue);
2223
const inputRef = React.useRef<HTMLInputElement | null>(null);
2324
const { setPreviousSelectionStart } = useInputSelection(
2425
inputRef,

src/react/table-app/number-cell-edit/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22

33
import { useCompare, useInputSelection } from "src/shared/hooks";
4-
import { isValidNumberInput } from "src/shared/validators";
4+
import { isNumber, isValidNumberInput } from "src/shared/validators";
55
import { MenuCloseRequest } from "src/shared/menu/types";
66
import { numberInputStyle } from "src/react/table-app/shared-styles";
77

@@ -18,7 +18,8 @@ export default function NumberCellEdit({
1818
onChange,
1919
onMenuClose,
2020
}: Props) {
21-
const [localValue, setLocalValue] = React.useState(value);
21+
const initialValue = isNumber(value) ? value : "";
22+
const [localValue, setLocalValue] = React.useState(initialValue);
2223
const inputRef = React.useRef<HTMLInputElement | null>(null);
2324
const { setPreviousSelectionStart } = useInputSelection(
2425
inputRef,

src/shared/export/cell-content.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,17 @@ export const getEmbedContent = (markdown: string) => {
4646
return markdown;
4747
};
4848

49+
export const getNumberCellContent = (value: string) => {
50+
if (isNumber(value)) return value;
51+
return "";
52+
};
53+
4954
export const getCurrencyCellContent = (
5055
value: string,
5156
currencyType: CurrencyType
5257
) => {
5358
if (isNumber(value)) return stringToCurrencyString(value, currencyType);
54-
return value;
59+
return "";
5560
};
5661

5762
export const getCellContent = (
@@ -62,8 +67,9 @@ export const getCellContent = (
6267
switch (column.type) {
6368
case CellType.TEXT:
6469
case CellType.FILE:
65-
case CellType.NUMBER:
6670
return cell.markdown;
71+
case CellType.NUMBER:
72+
return getNumberCellContent(cell.markdown);
6773
case CellType.EMBED:
6874
return getEmbedContent(cell.markdown);
6975
case CellType.CHECKBOX:

0 commit comments

Comments
 (0)