From a3ee0dcd39c5ccce000ce4fc526056b0c2e21b44 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Tue, 29 Aug 2023 11:13:56 +0100 Subject: [PATCH] Merge pull request #14495 from overleaf/mj-table-gen-textarea [visual] Use textarea instead of input in table generator GitOrigin-RevId: 5d394f9978dc25bebf63f1cbd4f1c39466469843 --- .../components/table-generator/cell-input.tsx | 33 ++++++++++++++++++ .../components/table-generator/cell.tsx | 34 ++++++++++++------- .../components/table-generator/table.tsx | 2 +- .../extensions/visual/table-generator.ts | 6 +++- 4 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 services/web/frontend/js/features/source-editor/components/table-generator/cell-input.tsx 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