wwf
4 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
app/components/base/auto-height-textarea/index.tsx
@@ -1,4 +1,4 @@
import { useEffect, useRef } from 'react'
import { forwardRef, useEffect, useRef } from 'react'
import cn from '@/utils/classnames'
import { sleep } from '@/utils'
@@ -16,23 +16,10 @@
  onKeyUp?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void
}
const AutoHeightTextarea = (
  {
    ref: outerRef,
    value,
    onChange,
    placeholder,
    className,
    wrapperClassName,
    minHeight = 36,
    maxHeight = 96,
    autoFocus,
    controlFocus,
    onKeyDown,
    onKeyUp,
  }: IProps & {
    ref: React.RefObject<unknown>;
  },
const AutoHeightTextarea = forwardRef(
  (
    { value, onChange, placeholder, className, wrapperClassName, minHeight = 36, maxHeight = 96, autoFocus, controlFocus, onKeyDown, onKeyUp }: IProps,
    outerRef: any,
) => {
  // eslint-disable-next-line react-hooks/rules-of-hooks
  const ref = outerRef || useRef<HTMLTextAreaElement>(null)
@@ -66,8 +53,8 @@
  }, [controlFocus])
  return (
    (<div className={`relative ${wrapperClassName}`}>
      <div className={cn(className, 'invisible overflow-y-auto whitespace-pre-wrap  break-all')} style={{
      <div className={`relative ${wrapperClassName}`}>
        <div className={cn(className, 'invisible whitespace-pre-wrap break-all  overflow-y-auto')} style={{
        minHeight,
        maxHeight,
        paddingRight: (value && value.trim().length > 10000) ? 140 : 130,
@@ -87,9 +74,10 @@
        onKeyUp={onKeyUp}
        value={value}
      />
    </div>)
      </div>
  )
}
  },
)
AutoHeightTextarea.displayName = 'AutoHeightTextarea'