index.js 701 Bytes
Newer Older
田翔's avatar
田翔 committed
1 2 3
import React, { useState, useEffect, useMemo } from 'react'
import { Input } from 'antd'

4
const TextArea = (props) => {
田翔's avatar
田翔 committed
5

6
  const { value, onChange, schema, addons } = props
田翔's avatar
田翔 committed
7
  const { disabled, placeholder, presetValue, maxLength, rows } = schema
田翔's avatar
田翔 committed
8

田翔's avatar
田翔 committed
9
  useEffect(() => {
10 11 12 13 14
    if (addons) {
      addons.setValueByPath(addons.dataPath, presetValue)
    } else {
      onChange(presetValue)
    }
田翔's avatar
田翔 committed
15
  }, [presetValue])
田翔's avatar
田翔 committed
16

17

田翔's avatar
田翔 committed
18 19 20 21 22 23
  const handleChange = (e) => {
    onChange(e.target.value)
  }

  return (
    <Input.TextArea
田翔's avatar
田翔 committed
24
      maxLength={maxLength}
田翔's avatar
田翔 committed
25
      disabled={disabled}
田翔's avatar
田翔 committed
26
      value={value}
田翔's avatar
田翔 committed
27
      rows={rows}
田翔's avatar
田翔 committed
28 29 30 31 32 33 34
      placeholder={placeholder}
      onChange={handleChange}
    />
  )
}

export default TextArea