You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.1 KiB
65 lines
1.1 KiB
8 years ago
|
---
|
||
|
order: 3
|
||
|
title:
|
||
|
zh-CN: 自定义输入组件
|
||
|
en-US: Customize Input Component
|
||
|
---
|
||
|
|
||
|
## zh-CN
|
||
|
|
||
|
自定义输入组件。
|
||
|
|
||
|
## en-US
|
||
|
|
||
|
Customize Input Component
|
||
|
|
||
8 years ago
|
````jsx
|
||
7 years ago
|
import { AutoComplete, Input } from 'antd';
|
||
|
const { TextArea } = Input;
|
||
8 years ago
|
|
||
|
function onSelect(value) {
|
||
|
console.log('onSelect', value);
|
||
|
}
|
||
|
|
||
8 years ago
|
class Complete extends React.Component {
|
||
|
state = {
|
||
|
dataSource: [],
|
||
|
}
|
||
|
|
||
8 years ago
|
handleSearch = (value) => {
|
||
8 years ago
|
this.setState({
|
||
|
dataSource: !value ? [] : [
|
||
|
value,
|
||
|
value + value,
|
||
|
value + value + value,
|
||
|
],
|
||
|
});
|
||
8 years ago
|
}
|
||
|
|
||
|
handleKeyPress = (ev) => {
|
||
8 years ago
|
console.log('handleKeyPress', ev);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
render() {
|
||
|
const { dataSource } = this.state;
|
||
|
return (
|
||
|
<AutoComplete
|
||
|
dataSource={dataSource}
|
||
7 years ago
|
style={{ width: 200 }}
|
||
8 years ago
|
onSelect={onSelect}
|
||
8 years ago
|
onSearch={this.handleSearch}
|
||
8 years ago
|
>
|
||
7 years ago
|
<TextArea
|
||
|
placeholder="input here"
|
||
|
className="custom"
|
||
|
style={{ height: 50 }}
|
||
|
onKeyPress={this.handleKeyPress}
|
||
|
/>
|
||
8 years ago
|
</AutoComplete>
|
||
|
);
|
||
8 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
ReactDOM.render(<Complete />, mountNode);
|
||
|
````
|