|
|
|
@ -1,13 +1,13 @@
|
|
|
|
import { forwardRef, useEffect, useRef } from 'react'
|
|
|
|
import { useEffect, useRef } from 'react'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
|
|
|
|
|
|
|
|
type AutoHeightTextareaProps =
|
|
|
|
type AutoHeightTextareaProps =
|
|
|
|
& React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>
|
|
|
|
& React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>
|
|
|
|
& { outerClassName?: string }
|
|
|
|
& { outerClassName?: string }
|
|
|
|
|
|
|
|
|
|
|
|
const AutoHeightTextarea = forwardRef<HTMLTextAreaElement, AutoHeightTextareaProps>(
|
|
|
|
const AutoHeightTextarea = (
|
|
|
|
(
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ref: outRef,
|
|
|
|
outerClassName,
|
|
|
|
outerClassName,
|
|
|
|
value,
|
|
|
|
value,
|
|
|
|
className,
|
|
|
|
className,
|
|
|
|
@ -15,9 +15,10 @@ const AutoHeightTextarea = forwardRef<HTMLTextAreaElement, AutoHeightTextareaPro
|
|
|
|
autoFocus,
|
|
|
|
autoFocus,
|
|
|
|
disabled,
|
|
|
|
disabled,
|
|
|
|
...rest
|
|
|
|
...rest
|
|
|
|
|
|
|
|
}: AutoHeightTextareaProps & {
|
|
|
|
|
|
|
|
ref: React.RefObject<HTMLTextAreaElement>;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outRef,
|
|
|
|
) => {
|
|
|
|
) => {
|
|
|
|
|
|
|
|
const innerRef = useRef<HTMLTextAreaElement>(null)
|
|
|
|
const innerRef = useRef<HTMLTextAreaElement>(null)
|
|
|
|
const ref = outRef || innerRef
|
|
|
|
const ref = outRef || innerRef
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,7 +31,7 @@ const AutoHeightTextarea = forwardRef<HTMLTextAreaElement, AutoHeightTextareaPro
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [autoFocus, disabled, ref])
|
|
|
|
}, [autoFocus, disabled, ref])
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={outerClassName}>
|
|
|
|
(<div className={outerClassName}>
|
|
|
|
<div className='relative'>
|
|
|
|
<div className='relative'>
|
|
|
|
<div className={cn(className, 'invisible whitespace-pre-wrap break-all')}>
|
|
|
|
<div className={cn(className, 'invisible whitespace-pre-wrap break-all')}>
|
|
|
|
{!value ? placeholder : `${value}`.replace(/\n$/, '\n ')}
|
|
|
|
{!value ? placeholder : `${value}`.replace(/\n$/, '\n ')}
|
|
|
|
@ -44,10 +45,9 @@ const AutoHeightTextarea = forwardRef<HTMLTextAreaElement, AutoHeightTextareaPro
|
|
|
|
{...rest}
|
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AutoHeightTextarea.displayName = 'AutoHeightTextarea'
|
|
|
|
AutoHeightTextarea.displayName = 'AutoHeightTextarea'
|
|
|
|
|
|
|
|
|
|
|
|
|