@ -1,7 +1,8 @@
|
|||||||
import { ChangeEvent } from 'react';
|
import { ChangeEvent, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { InplaceInputTextDisplayMode } from '@/ui/inplace-inputs/components/InplaceInputTextDisplayMode';
|
import { InplaceInputTextDisplayMode } from '@/ui/inplace-inputs/components/InplaceInputTextDisplayMode';
|
||||||
import { InplaceInputTextEditMode } from '@/ui/inplace-inputs/components/InplaceInputTextEditMode';
|
import { InplaceInputTextEditMode } from '@/ui/inplace-inputs/components/InplaceInputTextEditMode';
|
||||||
|
import { debounce } from '@/utils/debounce';
|
||||||
|
|
||||||
import { EditableCell } from '../EditableCell';
|
import { EditableCell } from '../EditableCell';
|
||||||
|
|
||||||
@ -18,6 +19,12 @@ export function EditableCellText({
|
|||||||
onChange,
|
onChange,
|
||||||
editModeHorizontalAlign,
|
editModeHorizontalAlign,
|
||||||
}: OwnProps) {
|
}: OwnProps) {
|
||||||
|
const [internalValue, setInternalValue] = useState(value);
|
||||||
|
|
||||||
|
const debouncedOnChange = useMemo(() => {
|
||||||
|
return debounce(onChange, 200);
|
||||||
|
}, [onChange]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditableCell
|
<EditableCell
|
||||||
editModeHorizontalAlign={editModeHorizontalAlign}
|
editModeHorizontalAlign={editModeHorizontalAlign}
|
||||||
@ -25,14 +32,17 @@ export function EditableCellText({
|
|||||||
<InplaceInputTextEditMode
|
<InplaceInputTextEditMode
|
||||||
placeholder={placeholder || ''}
|
placeholder={placeholder || ''}
|
||||||
autoFocus
|
autoFocus
|
||||||
value={value}
|
value={internalValue}
|
||||||
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
||||||
onChange(event.target.value);
|
setInternalValue(event.target.value);
|
||||||
|
debouncedOnChange(event.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
nonEditModeContent={
|
nonEditModeContent={
|
||||||
<InplaceInputTextDisplayMode>{value}</InplaceInputTextDisplayMode>
|
<InplaceInputTextDisplayMode>
|
||||||
|
{internalValue}
|
||||||
|
</InplaceInputTextDisplayMode>
|
||||||
}
|
}
|
||||||
></EditableCell>
|
></EditableCell>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user