Skip to content

Commit 65a6681

Browse files
committed
docs: add allowClear documentation & examples
1 parent 5a8fb15 commit 65a6681

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

docs/api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ nav:
117117
<td>Number</td>
118118
<td></td>
119119
<td>Specifies the defaultValue of an InputNumber</td>
120+
</tr>
121+
<tr>
122+
<td>allowClear</td>
123+
<td>boolean | { clearIcon?: React.ReactNode; clearValue: T }</td>
124+
<td>false</td>
125+
<td>If allow to remove input content with clear icon</td>
126+
</tr>
127+
<tr>
128+
<td>onClear</td>
129+
<td>Function</td>
130+
<td></td>
131+
<td>Called when value of an InputNumber cleared</td>
120132
</tr>
121133
<tr>
122134
<td>onChange</td>

docs/demo/allow-clear.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* eslint no-console:0 */
2+
import InputNumber from '@rc-component/input-number';
3+
import React from 'react';
4+
import '../../assets/index.less';
5+
6+
export default () => {
7+
const [value, setValue] = React.useState<string | number>(100);
8+
9+
const onChange = (val: number) => {
10+
console.log('onChange:', val, typeof val);
11+
setValue(val);
12+
};
13+
14+
return (
15+
<div style={{ margin: 10 }}>
16+
<InputNumber style={{ width: 200 }} value={value} onChange={onChange} allowClear={true} />
17+
18+
<hr />
19+
<h3>with suffix</h3>
20+
21+
<InputNumber
22+
style={{ width: 200 }}
23+
value={value}
24+
onChange={onChange}
25+
prefix="¥"
26+
suffix="RMB"
27+
allowClear={true}
28+
/>
29+
30+
<hr />
31+
<h3>with custom clear value</h3>
32+
33+
<InputNumber
34+
style={{ width: 200 }}
35+
value={value}
36+
onChange={onChange}
37+
prefix="¥"
38+
suffix="RMB"
39+
allowClear={{ clearValue: 1 }}
40+
/>
41+
42+
<hr />
43+
<h3>with custom clear icon</h3>
44+
45+
<InputNumber
46+
style={{ width: 200 }}
47+
value={value}
48+
onChange={onChange}
49+
prefix="¥"
50+
suffix="RMB"
51+
allowClear={{ clearIcon: <span style={{ color: 'red' }}>clear</span> }}
52+
/>
53+
</div>
54+
);
55+
};

docs/example.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ nav:
6060
## spinner
6161

6262
<code src="./demo/spinner.tsx"></code>
63+
64+
## allow-clear
65+
66+
<code src="./demo/allow-clear.tsx"></code>

0 commit comments

Comments
 (0)