diff --git a/src/renderers/Form/InputText.tsx b/src/renderers/Form/InputText.tsx
index 55120ddba..273ecd5da 100644
--- a/src/renderers/Form/InputText.tsx
+++ b/src/renderers/Form/InputText.tsx
@@ -634,7 +634,7 @@ export default class TextControl extends React.PureComponent<
onClick={this.clearValue}
className={cx('TextControl-clear')}
>
-
+
) : null}
@@ -740,7 +740,7 @@ export default class TextControl extends React.PureComponent<
/>
{clearable && !disabled && value ? (
-
+
) : null}
{showCounter ? (
diff --git a/src/renderers/Form/Picker.tsx b/src/renderers/Form/Picker.tsx
index d62b617b1..f72637711 100644
--- a/src/renderers/Form/Picker.tsx
+++ b/src/renderers/Form/Picker.tsx
@@ -469,7 +469,7 @@ export default class PickerControl extends React.PureComponent<
{clearable && !disabled && selectedOptions.length ? (
-
+
) : null}
diff --git a/src/renderers/Form/Textarea.tsx b/src/renderers/Form/Textarea.tsx
index 710dae1fd..9c837b4f4 100644
--- a/src/renderers/Form/Textarea.tsx
+++ b/src/renderers/Form/Textarea.tsx
@@ -2,6 +2,7 @@ import React from 'react';
import {FormItem, FormControlProps, FormBaseControl} from './Item';
import cx from 'classnames';
import Textarea from '../../components/Textarea';
+import {Icon} from '../../components/icons';
import {findDOMNode} from 'react-dom';
import {autobind, ucFirst} from '../../utils/helper';
/**
@@ -43,12 +44,24 @@ export interface TextareaControlSchema extends FormBaseControl {
* 是否显示计数
*/
showCounter?: boolean;
+
+ /**
+ * 输入内容是否可清除
+ */
+ clearable?: boolean;
+
+ /**
+ * 重置值
+ */
+ resetValue?: string;
}
export interface TextAreaProps extends FormControlProps {
placeholder?: string;
minRows?: number;
maxRows?: number;
+ clearable?: boolean;
+ resetValue?: string;
}
export default class TextAreaControl extends React.Component<
@@ -58,7 +71,9 @@ export default class TextAreaControl extends React.Component<
static defaultProps: Partial
= {
minRows: 3,
maxRows: 20,
- trimContents: true
+ trimContents: true,
+ resetValue: '',
+ clearable: false
};
state = {
@@ -68,6 +83,14 @@ export default class TextAreaControl extends React.Component<
input?: HTMLInputElement;
inputRef = (ref: any) => (this.input = findDOMNode(ref) as HTMLInputElement);
+ valueToString(value: any) {
+ return typeof value === 'undefined' || value === null
+ ? ''
+ : typeof value === 'string'
+ ? value
+ : JSON.stringify(value);
+ }
+
focus() {
if (!this.input) {
return;
@@ -132,6 +155,14 @@ export default class TextAreaControl extends React.Component<
);
}
+ @autobind
+ handleClear() {
+ const {onChange, resetValue} = this.props;
+
+ onChange?.(resetValue);
+ this.focus();
+ }
+
render() {
const {
className,
@@ -147,17 +178,10 @@ export default class TextAreaControl extends React.Component<
borderMode,
classnames: cx,
maxLength,
- showCounter
+ showCounter,
+ clearable
} = this.props;
-
- let counter = showCounter
- ? (typeof value === 'undefined' || value === null
- ? ''
- : typeof value === 'string'
- ? value
- : JSON.stringify(value)
- ).length
- : 0;
+ const counter = showCounter ? this.valueToString(value).length : 0;
return (
+ {clearable && !disabled && value ? (
+
+
+
+ ) : null}
+
{showCounter ? (
{`${counter}${
typeof maxLength === 'number' && maxLength ? `/${maxLength}` : ''