forked from react-component/select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombobox.js
69 lines (61 loc) · 1.57 KB
/
combobox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint no-console: 0 */
import React from 'react';
import ReactDOM from 'react-dom';
import Select, { Option } from 'rc-select';
import 'rc-select/assets/index.less';
class Demo extends React.Component {
state = {
disabled: false,
value: '',
};
onChange = (value, option) => {
console.log('onChange', value, option);
this.setState({
value,
});
}
onKeyDown = (e) => {
if (e.keyCode === 13) {
console.log('onEnter', this.state.value);
}
}
onSelect = (v, option) => {
console.log('onSelect', v, option);
}
toggleDisabled = () => {
this.setState({
disabled: !this.state.disabled,
});
}
render() {
return (<div>
<h2>combobox</h2>
<p>
<button onClick={this.toggleDisabled}>toggle disabled</button>
</p>
<div style={{ width: 300 }}>
<Select
disabled={this.state.disabled}
style={{ width: 500 }}
onChange={this.onChange}
onSelect={this.onSelect}
onInputKeyDown={this.onKeyDown}
notFoundContent=""
allowClear
placeholder="please select"
value={this.state.value}
combobox
backfill
>
<Option value="jack">
<b style={{ color: 'red' }}>jack</b>
</Option>
<Option value="lucy">lucy</Option>
<Option value="disabled" disabled>disabled</Option>
<Option value="yiminghe">yiminghe</Option>
</Select>
</div>
</div>);
}
}
ReactDOM.render(<Demo />, document.getElementById('__react-content'));