EmailField电子邮件输入框
电子邮件输入框。
何时使用
代码演示
基本使用。
import { EmailField, Row, Col } from 'choerodon-ui/pro';
function log(value) {
console.log('[basic]', value);
}
ReactDOM.render(
<Row gutter={10}>
<Col span={8}>
<EmailField placeholder="请输入" onChange={log} />
</Col>
<Col span={8}>
<EmailField placeholder="清除按钮" defaultValue="点击清除" clearButton onChange={log} />
</Col>
<Col span={8}>
<EmailField value="不可用" disabled />
</Col>
</Row>,
mountNode
);
绑定数据源。
import { DataSet, EmailField } 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: 'email', type: 'email', defaultValue: '123@abc.com', required: true },
],
events: {
update: handleDataSetChange,
},
});
render() {
return <EmailField dataSet={this.ds} name="email" />;
}
}
ReactDOM.render(
<App />,
mountNode
);
受控输入框
import { EmailField } from 'choerodon-ui/pro';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
value: 'abc@123.com',
};
}
handleChange = (value, oldValue) => {
console.log('[newValue]', value, '[oldValue]', oldValue);
this.setState({
value,
});
}
handleInput = (e) => {
console.log('[input]', e.target.value);
}
render() {
return <EmailField value={this.state.value} onChange={this.handleChange} onInput={this.handleInput} />;
}
}
ReactDOM.render(
<App />,
mountNode
);
API
EmailField
更多属性请参考 TextField。