From 100910a07286e4782b4aa911f5cef391bc0fa5c5 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 5 Apr 2021 09:23:29 +0100 Subject: [PATCH] =?UTF-8?q?[15=20min=20fix]=20=E2=9C=82=EF=B8=8F=E2=9C=82?= =?UTF-8?q?=EF=B8=8F=E2=9C=82=EF=B8=8F=20Remove=20preact-textarea-autosize?= =?UTF-8?q?=20library=20=E2=9C=82=EF=B8=8F=E2=9C=82=EF=B8=8F=E2=9C=82?= =?UTF-8?q?=EF=B8=8F=20(#13234)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove lib from title component, use hook instead * remove lib from chat compose, and remove package --- .../article-form/components/Title.jsx | 23 +++++++++++++------ app/javascript/chat/compose.jsx | 22 +++++++++++++++--- package.json | 1 - yarn.lock | 5 ---- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/javascript/article-form/components/Title.jsx b/app/javascript/article-form/components/Title.jsx index 26f70e7e6..eacb03249 100644 --- a/app/javascript/article-form/components/Title.jsx +++ b/app/javascript/article-form/components/Title.jsx @@ -1,23 +1,32 @@ import { h } from 'preact'; +import { useRef, useLayoutEffect } from 'preact/hooks'; import PropTypes from 'prop-types'; -// We use this magic Textarea component for title field because it's automatically -// resizable. Even though it looks like a classic input, if you enter long title -// it would wrap the text to the next line automatically resizing itself. It helps keep -// the entire layout the way it is without having unnecessary scrolling and white spaces. -// Keep in mind this is what happens only here - in preact component. +// We use this hook for the title field to automatically grow the height of the textarea. +// It helps keep the entire layout the way it is without having unnecessary scrolling and white spaces. +// Keep in mind this is what happens only here - in the Preact component. // I'm mentioning this because the entire "Write a post" view is a preact component // BUT it is also a classic .html.erb view which is being loaded BEFORE this component // to give a feeling of blazing fast page load. And we do NOT use this magic autoresizing // functionality on .html.erb view because there's no point of it. -import Textarea from 'preact-textarea-autosize'; +import { useTextAreaAutoResize } from '@utilities/textAreaUtils'; export const Title = ({ onChange, defaultValue, switchHelpContext }) => { + const textAreaRef = useRef(null); + const { setTextArea } = useTextAreaAutoResize(); + + useLayoutEffect(() => { + if (textAreaRef.current) { + setTextArea(textAreaRef.current); + } + }, [setTextArea]); + return (
-