/
single.tsx
155 lines (141 loc) · 3.57 KB
/
single.tsx
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* eslint-disable no-console */
import React from 'react';
import Select, { Option } from '../src';
import '../assets/index.less';
import './single.less';
class Test extends React.Component {
state = {
destroy: false,
value: '9',
};
onChange = e => {
let value;
if (e && e.target) {
({ value } = e.target);
} else {
value = e;
}
console.log('onChange', value);
this.setState({
value,
});
};
onDestroy = () => {
this.setState({
destroy: 1,
});
};
onBlur = v => {
console.log('onBlur', v);
};
onFocus = () => {
console.log('onFocus');
};
onSearch = val => {
console.log('Search:', val);
};
render() {
const { value, destroy } = this.state;
if (destroy) {
return null;
}
return (
<div style={{ margin: 20 }}>
<div
style={{ height: 150, background: 'rgba(0, 255, 0, 0.1)' }}
onMouseDown={e => {
e.preventDefault();
}}
>
Prevent Default
</div>
<h2>Single Select</h2>
<div style={{ width: 300 }}>
<Select
autoFocus
id="my-select"
value={value}
placeholder="placeholder"
showSearch={false}
style={{ width: 500 }}
onBlur={this.onBlur}
onFocus={this.onFocus}
onSearch={this.onSearch}
allowClear
optionFilterProp="text"
onChange={this.onChange}
backfill
onPopupScroll={() => {
console.log('Scroll!');
}}
>
<Option value={null}>不选择</Option>
<Option value="01" text="jack" title="jack">
<b
style={{
color: 'red',
}}
>
jack
</b>
</Option>
<Option value="11" text="lucy">
lucy
</Option>
<Option value="21" disabled text="disabled">
disabled
</Option>
<Option
value="31"
text="yiminghe"
className="test-option"
style={{ background: 'yellow' }}
>
yiminghe
</Option>
{[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
<Option key={i} value={String(i)} text={String(i)}>
{i}-text
</Option>
))}
</Select>
</div>
<h2>native select</h2>
<select value={value} style={{ width: 500 }} onChange={this.onChange}>
<option value="01">jack</option>
<option value="11">lucy</option>
<option value="21" disabled>
disabled
</option>
<option value="31">yiminghe</option>
{[1, 2, 3, 4, 5, 6, 7, 8, 9].map(i => (
<option value={i} key={i}>
{i}
</option>
))}
</select>
<h2>RTL Select</h2>
<div style={{ width: 300 }}>
<Select
id="my-select-rtl"
placeholder="rtl"
direction="rtl"
dropdownMatchSelectWidth={300}
dropdownStyle={{ minWidth: 300 }}
style={{ width: 500 }}
>
<Option value="1">1</Option>
<Option value="2">2</Option>
</Select>
</div>
<p>
<button type="button" onClick={this.onDestroy}>
destroy
</button>
</p>
</div>
);
}
}
export default Test;
/* eslint-enable */