Skip to content

Commit

Permalink
fix: textarea auto layout 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
ymj07168 committed May 23, 2024
1 parent e63dae4 commit d6d07cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Experience/YearList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const YearList = ({ width, openDeleteModal }: YearListProps) => {
return index * 250 + 250;
}
if (index > hoveredIndex) {
return index * 250 + distance + 100;
return index * 250 + distance;
}
}
if (hoveredYear) {
Expand Down
26 changes: 24 additions & 2 deletions src/components/common/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextareaHTMLAttributes } from "react";
import React, { TextareaHTMLAttributes, useRef } from "react";
import styled from "styled-components";

interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
Expand All @@ -16,6 +16,24 @@ const Textarea = ({
helperTextStyle,
...props
}: TextareaProps) => {
const textareaRef = React.useRef<HTMLTextAreaElement>(null);

const adjustTextareaHeight = (textarea: HTMLTextAreaElement) => {
textarea.style.height = "auto";
textarea.style.height = textarea.scrollHeight + "px";
};

const handleInput = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
adjustTextareaHeight(event.target);
};

React.useEffect(() => {
const textarea = textareaRef.current;
if (textarea) {
adjustTextareaHeight(textarea);
}
}, []);

return (
<InputContainer labelStyle={labelStyle} helperTextStyle={helperTextStyle}>
{label && (
Expand All @@ -27,7 +45,7 @@ const Textarea = ({
</div>
)}
{helperText && <div className="helperText">{helperText}</div>}
<InputBox {...props} />
<InputBox {...props} ref={textareaRef} onInput={handleInput} />
</InputContainer>
);
};
Expand Down Expand Up @@ -73,6 +91,10 @@ const InputBox = styled.textarea`
border: 2px solid ${(props) => props.theme.colors.main500};
padding: 15px;
}
&.scroll::-webkit-scrollbar {
display: none;
}
overflow-y: hidden;
`;

export default Textarea;
1 change: 0 additions & 1 deletion src/pages/ExperienceDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const ExperienceDetailPage = () => {
<Textarea
value={item.answer}
label={`${index + 1}. ${item.question}`}
rows={8}
labelStyle={
theme.fonts.title4 + `color: ${theme.colors.neutral700}`
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/ExperienceEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ const ExperienceEditPage = () => {
required={index === 0 || index === 1}
value={expData.contents[index].answer}
label={`${index + 1}. ${item.question}`}
rows={8}
labelStyle={
theme.fonts.title4 + `color: ${theme.colors.neutral700}`
}
Expand Down

0 comments on commit d6d07cf

Please sign in to comment.