UNPKG

9.28 kBMarkdownView Raw
1# rc-input ⌨️
2
3[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![Dependencies][david-image]](david-url) [![DevDependencies][david-dev-image]][david-dev-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
4
5[npm-image]: http://img.shields.io/npm/v/rc-input.svg?style=flat-square
6[npm-url]: http://npmjs.org/package/rc-input
7[github-actions-image]: https://github.com/react-component/input/workflows/CI/badge.svg
8[github-actions-url]: https://github.com/react-component/input/actions
9[codecov-image]: https://img.shields.io/codecov/c/github/react-component/input/master.svg?style=flat-square
10[codecov-url]: https://codecov.io/gh/react-component/input/branch/master
11[david-url]: https://david-dm.org/react-component/input
12[david-image]: https://david-dm.org/react-component/input/status.svg?style=flat-square
13[david-dev-url]: https://david-dm.org/react-component/input?type=dev
14[david-dev-image]: https://david-dm.org/react-component/input/dev-status.svg?style=flat-square
15[download-image]: https://img.shields.io/npm/dm/rc-input.svg?style=flat-square
16[download-url]: https://npmjs.org/package/rc-input
17[bundlephobia-url]: https://bundlephobia.com/result?p=rc-input
18[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-input
19
20## Install
21
22[![rc-input](https://nodei.co/npm/rc-input.png)](https://npmjs.org/package/rc-input)
23
24## Usage
25
26```js
27import Input from 'rc-input';
28import { render } from 'react-dom';
29
30render(<Input placeholder="input" allowClear />, mountNode);
31```
32
33## API
34
35| Property | Type | Default | Description |
36| --------------------- | ---------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37| prefixCls | string | rc-input | |
38| className | string | '' | additional class name of input |
39| style | React.CSSProperties | | style properties of input |
40| affixWrapperClassName | string | - | className with 'rc-input-affix-wrapper' |
41| groupClassName | string | - | className with 'rc-input-group-wrapper' |
42| wrapperClassName | string | - | className with 'rc-input-wrapper' |
43| addonAfter | ReactNode | - | The label text displayed after (on the right side of) the input field |
44| addonBefore | ReactNode | - | The label text displayed before (on the left side of) the input field |
45| allowClear | boolean &#124; { clearIcon: ReactNode } | false | If allow to remove input content with clear icon |
46| bordered | boolean | true | Whether has border style |
47| defaultValue | string | - | The initial input content |
48| disabled | boolean | false | Whether the input is disabled |
49| id | string | - | The ID for input |
50| maxLength | number | - | The max length |
51| showCount | boolean &#124; { formatter: ({ value: string, count: number, maxLength?: number }) => ReactNode } | false | Whether show text count |
52| prefix | ReactNode | - | The prefix icon for the Input |
53| suffix | ReactNode | - | The suffix icon for the Input |
54| type | string | `text` | The type of input, see: [MDN](https://developer.mozilla.org/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types)( use `Input.TextArea` instead of `type="textarea"`) |
55| value | string | - | The input content value |
56| onChange | function(e) | - | Callback when user input |
57| onPressEnter | function(e) | - | The callback function that is triggered when Enter key is pressed |
58
59## inputRef
60
61```tsx | pure
62const inputRef = useRef(null);
63
64useEffect(() => {
65 inputRef.current.focus();// the input will get focus
66 inputRef.current.blur();// the input will lose focus
67 console.log(inputRef.current.input);// The origin input element
68}, []);
69// ....
70<Input ref={inputRef} />
71```
72
73| Property | Type | Description |
74| -------- | --------------------------------------- | --------------------------------- |
75| focus | `(options?: InputFocusOptions) => void` | The input get focus when called |
76| blur | `() => void` | The input loses focus when called |
77| input | `HTMLInputElement \| null` | The origin input element |
78
79
80
81## Development
82
83```
84npm install
85npm start
86```
87
88## License
89
90rc-input is released under the MIT license.