TextArea文本域
文本域用于输入一段文字。
何时使用
代码演示
基本使用。
import { TextArea, Row, Col } from 'choerodon-ui/pro';
ReactDOM.render(
<Row gutter={10}>
<Col span={8}>
<TextArea placeholder="Basic usage" />
</Col>
<Col span={8}>
<TextArea placeholder="readOnly" readOnly />
</Col>
<Col span={8}>
<TextArea placeholder="disabled" disabled />
</Col>
</Row>,
mountNode,
);
数据绑定
import { TextArea, DataSet } from 'choerodon-ui/pro';
function handleDataSetChange({ record, name, value, oldValue }) {
console.log('[dataset newValue]', value, '[oldValue]', oldValue, `[record.get('${name}')]`, record.get(name));
}
class App extends React.Component {
ds = new DataSet({
autoCreate: true,
fields: [
{ name: 'content', type: 'string', defaultValue: 'textarea', required: true },
],
events: {
update: handleDataSetChange,
},
});
render() {
return <TextArea dataSet={this.ds} name="content" resize="both" />;
}
}
ReactDOM.render(
<App />,
mountNode
);
受控输入框
import { TextArea } from 'choerodon-ui/pro';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
value: 'default',
};
}
handleChange = (value, oldValue) => {
console.log('[newValue]', value, '[oldValue]', oldValue);
this.setState({
value,
});
}
handleInput = (e) => {
console.log('[textarea]', e.target.value);
}
render() {
return <TextArea value={this.state.value} onChange={this.handleChange} onInput={this.handleInput} />;
}
}
ReactDOM.render(
<App />,
mountNode
);
拖拽调整大小
import { TextArea, Row, Col } from 'choerodon-ui/pro';
ReactDOM.render(
<Row gutter={10}>
<Col span={8}>
<TextArea placeholder="resize both" resize="both" cols={40} />
</Col>
<Col span={8}>
<TextArea placeholder="resize vertical" resize="vertical" cols={40} />
</Col>
<Col span={8}>
<TextArea placeholder="resize horizontal" resize="horizontal" cols={40} />
</Col>
</Row>,
mountNode
);
API
TextArea
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
cols | 文本域宽 | number | - |
rows | 文本域高 | number | - |
resize | 是否能够拖拽调整大小,可选值: none both vertical horizontal | string | none |
更多属性请参考 FormField。