Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix page reflow on Firefox and Safari #562

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/components/Chat/ChatContent/Message/View/EditView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EditView = ({
content,
setIsEdit,
messageIndex,
sticky,
sticky
}: {
content: string;
setIsEdit: React.Dispatch<React.SetStateAction<boolean>>;
Expand All @@ -28,6 +28,7 @@ const EditView = ({
const [_content, _setContent] = useState<string>(content);
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const textareaRef = React.createRef<HTMLTextAreaElement>();
const bufferRef = React.createRef<HTMLTextAreaElement>();

const { t } = useTranslation();

Expand Down Expand Up @@ -105,18 +106,23 @@ const EditView = ({
handleSubmit();
};

useEffect(() => {
if (textareaRef.current) {
textareaRef.current.style.height = 'auto';
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;
const adjustTextareaHeight = () => {
if (textareaRef.current && bufferRef.current) {
const textarea = textareaRef.current;
const buffer = bufferRef.current;

buffer.style.height = 'auto';
buffer.style.height = buffer.scrollHeight + 'px';
textarea.style.height = buffer.scrollHeight + 'px';
}
};

useEffect(() => {
adjustTextareaHeight();
}, [_content]);

useEffect(() => {
if (textareaRef.current) {
textareaRef.current.style.height = 'auto';
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;
}
adjustTextareaHeight();
}, []);

return (
Expand All @@ -128,6 +134,7 @@ const EditView = ({
: ''
}`}
>
<div className="relative">
<textarea
ref={textareaRef}
className='m-0 resize-none rounded-lg bg-transparent overflow-y-hidden focus:ring-0 focus-visible:ring-0 leading-7 w-full placeholder:text-gray-500/40'
Expand All @@ -139,6 +146,19 @@ const EditView = ({
onKeyDown={handleKeyDown}
rows={1}
></textarea>
<textarea
ref={bufferRef}
className='m-0 resize-none rounded-lg bg-transparent overflow-y-hidden focus:ring-0 focus-visible:ring-0 leading-7 w-full placeholder:text-gray-500/40 absolute top-0 left-0'
style={{
position: 'absolute',
visibility: 'hidden',
overflow: 'hidden'
}}
value={_content}
readOnly
rows={1}
></textarea>
</div>
</div>
<EditViewButtons
sticky={sticky}
Expand Down