Skip to content

Commit

Permalink
hook v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Schwehn42 committed May 8, 2024
1 parent 0d9e380 commit e2fccb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
.note-dialog__note-content--text {
background: none;
margin: 0;
overflow-y: auto;
@include scrollbar();
max-height: 500px;
overflow-y: scroll;
// @include scrollbar();
width: 100%;
color: $color-black;
letter-spacing: $letter-spacing--medium;
Expand Down
11 changes: 4 additions & 7 deletions src/utils/hooks/useTextAreaSize.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React, {useEffect} from "react";
import {MutableRefObject, useEffect} from "react";

// Updates the height of a <textarea> when the value changes.
const useAutosizeTextArea = (textAreaRef: React.MutableRefObject<HTMLTextAreaElement | null>, value: string) => {
const useAutosizeTextArea = (textAreaRef: MutableRefObject<HTMLTextAreaElement | null>, value: string) => {
useEffect(() => {
if (textAreaRef && textAreaRef.current) {
const element = textAreaRef.current;
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
element.style.height = "0px";
element.style.height = "auto";
const {scrollHeight} = element;

// We then set the height directly, outside the render loop
// Trying to set this with state or a ref will product an incorrect value.
element.style.height = `${scrollHeight }px`;
element.style.height = `${scrollHeight + 2}px`;
}
}, [textAreaRef, value]);
};
Expand Down

0 comments on commit e2fccb7

Please sign in to comment.