@material/react-text-field
Version:
Material Components React Text Field
60 lines (44 loc) • 1.87 kB
Markdown
MDC React Text Field Character Counter is a React Component which uses [MDC Text Field Character Counter](https://github.com/material-components/material-components-web/tree/master/packages/mdc-textfield/character-counter)'s Sass and Foundational JavaScript logic.
```js
import CharacterCounter from '@material/react-text-field/character-counter/index.js';
const MyComponent = () => {
return (
<CharacterCounter />
);
}
```
Prop Name | Type | Description
--- | --- | ---
className | String | CSS classes for element.
template | String | You can set custom template. [See below](
CharacterCounter provides customization with the `template` prop in CharacterCounter.
The `template` prop accepts the `${count}` and `${maxLength}` arguments.
The default template is `${count} / ${maxLength}`, so it appears `0 / 140`.
If you set template as `${count} : ${maxLength}`, it appears as `0 : 140`.
``` js
import React from 'react';
import TextField, {CharacterCounter, Input} from '@material/react-text-field';
class MyApp extends React.Component {
state = {value: 'Happy Coding!'};
render() {
return (
<TextField characterCounter={<CharacterCounter template='${count} : ${maxLength}' />}>
<Input
maxLength={140}
value={this.state.value}
onChange={(e) => this.setState({value: e.target.value})}
/>
</TextField>
);
}
}
```
Sass mixins may be available to customize various aspects of the Components. Please refer to the
MDC Web repository for more information on what mixins are available, and how to use them.
[](https://github.com/material-components/material-components-web/tree/master/packages/mdc-textfield/character-counter#sass-mixins)