Skip to content

Commit

Permalink
refactor: new yorker text-area to initial
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyEra committed Oct 5, 2023
1 parent fe45978 commit 7c8fa95
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions apps/www/registry/new-york/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
import * as React from "react";
import { cn } from "@/lib/utils";
import { useRef, useEffect } from 'react'
import { mergeRefs } from "react-merge-refs";
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> { }
import * as React from "react"

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
const texteAreaRef = useRef<HTMLTextAreaElement>(null);

useEffect(() => {
const ref = texteAreaRef?.current;

const updateTextareaHeight = () => {
if (ref) {
ref.style.height = "auto";
ref.style.height = ref?.scrollHeight + "px";
}
};
import { cn } from "@/lib/utils"

updateTextareaHeight();
ref?.addEventListener("input", updateTextareaHeight);

return () => ref?.removeEventListener("input", updateTextareaHeight);
}, []);
export interface TextareaProps
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={mergeRefs([texteAreaRef, ref])}
ref={ref}
{...props}
/>
);
)
}
);

Textarea.displayName = "Textarea";
)
Textarea.displayName = "Textarea"

export { Textarea };
export { Textarea }

0 comments on commit 7c8fa95

Please sign in to comment.