Skip to content

Instantly share code, notes, and snippets.

@JTRNS
Created June 30, 2023 15:36
Show Gist options
  • Save JTRNS/d7b0ec4ccead6cb215dd29b3d2ef8cab to your computer and use it in GitHub Desktop.
Save JTRNS/d7b0ec4ccead6cb215dd29b3d2ef8cab to your computer and use it in GitHub Desktop.
InputArea Component
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;
}
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