mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
Cast number inputs before save
This commit is contained in:
@@ -4,6 +4,7 @@ import { spreadSx } from "@src/utils/ui";
|
||||
|
||||
export interface IEditorCellTextFieldProps extends IEditorCellProps<string> {
|
||||
InputProps?: Partial<InputBaseProps>;
|
||||
onBlur?: () => void;
|
||||
}
|
||||
|
||||
export default function EditorCellTextField({
|
||||
@@ -11,6 +12,7 @@ export default function EditorCellTextField({
|
||||
value,
|
||||
onDirty,
|
||||
onChange,
|
||||
onBlur,
|
||||
setFocusInsideCell,
|
||||
InputProps = {},
|
||||
}: IEditorCellTextFieldProps) {
|
||||
@@ -19,7 +21,12 @@ export default function EditorCellTextField({
|
||||
return (
|
||||
<InputBase
|
||||
value={value}
|
||||
onBlur={() => onDirty()}
|
||||
onBlur={() => {
|
||||
if (onBlur) {
|
||||
onBlur();
|
||||
}
|
||||
onDirty();
|
||||
}}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
fullWidth
|
||||
autoFocus
|
||||
@@ -42,6 +49,11 @@ export default function EditorCellTextField({
|
||||
setTimeout(() => setFocusInsideCell(false));
|
||||
}
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
// Trigger an onBlur in case we have any final mutations
|
||||
if (onBlur) {
|
||||
onBlur();
|
||||
}
|
||||
|
||||
// Removes focus from inside cell, triggering save on unmount
|
||||
setFocusInsideCell(false);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ export default function Number_(props: IEditorCellProps<number | string>) {
|
||||
const parsedValue = v === "" ? v : Number(v);
|
||||
props.onChange(parsedValue);
|
||||
}}
|
||||
onBlur={() => {
|
||||
// Cast to number when the user has finished editing
|
||||
props.onChange(Number(props.value));
|
||||
props.onDirty();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,11 @@ export default function Number_({
|
||||
e.target.value === "" ? e.target.value : Number(e.target.value);
|
||||
onChange(parsedValue);
|
||||
}}
|
||||
onBlur={onSubmit}
|
||||
onBlur={() => {
|
||||
// Cast to number when the user has finished editing
|
||||
onChange(Number(value));
|
||||
onSubmit();
|
||||
}}
|
||||
value={value}
|
||||
id={getFieldId(column.key)}
|
||||
label=""
|
||||
|
||||
Reference in New Issue
Block a user