Created
June 30, 2023 15:36
-
-
Save JTRNS/d7b0ec4ccead6cb215dd29b3d2ef8cab to your computer and use it in GitHub Desktop.
InputArea Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div[data-autogrow]:has(textarea) { | |
display: grid; | |
} | |
div[data-autogrow]:has(textarea)::after { | |
content: attr(data-autogrow) ' '; | |
white-space: pre-wrap; | |
visibility: hidden; | |
} | |
div[data-autogrow]:has(textarea) > textarea { | |
resize: none; | |
overflow: hidden; | |
} | |
div[data-autogrow]:has(textarea) > textarea, | |
div[data-autogrow]:has(textarea)::after { | |
grid-area: 1 / 1 / 2 / 2; | |
border: 1px solid black; | |
padding: 0.5rem; | |
font: inherit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { ComponentPropsWithoutRef } from "react"; | |
export interface InputAreaProps extends ComponentPropsWithoutRef<"textarea"> { | |
wrapperClass?: string; | |
} | |
export default function InputArea( | |
{ wrapperClass, ...props }: InputAreaProps | |
) { | |
return ( | |
<div className={wrapperClass} data-autogrow={props.value}> | |
<textarea {...props}></textarea> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment