|
Download wp-calypso/client/components/forms/counted-textarea/README.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/counted-textarea/README.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/forms/counted-textarea/README.md
-
curl -L -o README.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/counted-textarea/README.md
1.55 kB
| # Counted Textarea | |
| Counted Textarea is a React form component which renders a `<textarea />` accompanied by a character count display. | |
|  | |
| ## Usage | |
| `<CountedTextarea />` expects to be rendered as a [controlled component](https://facebook.github.io/react/docs/forms.html#controlled-components), meaning that it will only behave as expected if passed a `value` prop. The textarea will automatically keep the character count in sync as the value prop is changed. With the exception of `className`, all props will be transferred to the child `<textarea />`. If a `className` prop is passed, it will be applied to the wrapper node. | |
| ```jsx | |
| import { Component } from 'react'; | |
| import CountedTextarea from 'calypso/components/forms/counted-textarea'; | |
| class MyComponent extends Component { | |
| state = { | |
| value: '', | |
| }; | |
| onChange = ( event ) => { | |
| this.setState( { value: event.target.value } ); | |
| }; | |
| render() { | |
| return <CountedTextarea value={ this.state.value } onChange={ this.onChange } />; | |
| } | |
| } | |
| export default MyComponent; | |
| ``` | |
| ## Props | |
| The following props are made available: | |
| ### `className` | |
| If a `className` prop is passed, it will be applied to the wrapper node. | |
| ### `acceptableLength` | |
| If passed and the value of the input exceeds the acceptable character count length, warning styles will be applied to the rendered output. If a maximum length is desired, use the browser default [`maxLength` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textareaattr-maxlength). | |