diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/cell-input.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/cell-input.tsx new file mode 100644 index 0000000000..eea425223c --- /dev/null +++ b/services/web/frontend/js/features/source-editor/components/table-generator/cell-input.tsx @@ -0,0 +1,33 @@ +import { forwardRef, useImperativeHandle, useLayoutEffect, useRef } from 'react' + +interface CellInputProps + extends React.TextareaHTMLAttributes { + value: string +} + +export type CellInputRef = { + focus: () => void +} + +export const CellInput = forwardRef( + function CellInput({ value, ...props }: CellInputProps, ref) { + const inputRef = useRef(null) + useImperativeHandle(ref, () => { + return { + focus() { + inputRef.current?.focus() + inputRef.current?.setSelectionRange(value.length, value.length) + }, + } + }) + + useLayoutEffect(() => { + if (inputRef?.current) { + inputRef.current.style.height = '1px' + inputRef.current.style.height = `${inputRef.current.scrollHeight}px` + } + }, [value]) + + return