# closure-react-text-field

> Material Components React Text Field

Latest version **0.7.9** (published 2018-12-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install closure-react-text-field
pnpm add closure-react-text-field
yarn add closure-react-text-field
bun add closure-react-text-field
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.9 |
| Published | 2018-12-26 |
| First published | 2018-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 888.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | yang_ji |
| Keywords | mdc web react, material components react, material design, text field, textfield |

## Links

- npm: https://www.npmjs.com/package/closure-react-text-field
- Repository: https://github.com/material-components/material-components-web-react
- Homepage: https://github.com/material-components/material-components-web-react#readme
- Issues: https://github.com/material-components/material-components-web-react/issues
- npm.io page: https://npm.io/package/closure-react-text-field

## Dependencies (7)

- [react](https://npm.io/package/react.md) ^16.4.2
- [classnames](https://npm.io/package/classnames.md) ^2.2.5
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.1
- [@material/textfield](https://npm.io/package/@material/textfield.md) ^0.41.0
- [closure-react-line-ripple](https://npm.io/package/closure-react-line-ripple.md) ^0.7.9
- [closure-react-floating-label](https://npm.io/package/closure-react-floating-label.md) ^0.7.9
- [closure-react-notched-outline](https://npm.io/package/closure-react-notched-outline.md) ^0.7.9

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.7.9 (latest) — 2018-12-26
- 0.7.8 — 2018-12-24
- 0.7.7 — 2018-12-21
- 0.7.6 — 2018-12-19
- 0.7.5 — 2018-12-19

## README

# React Text Field

MDC React Text Field is component for MDC Text Field. Please see [MDC Text Field](https://github.com/material-components/material-components-web/tree/master/packages/mdc-textfield/).

## Installation

```
npm install @material/react-text-field
```

## Usage

### Styles

with Sass:
```js
import '@material/react-text-field/index.scss';
```

with CSS:
```js
import '@material/react-text-field/dist/text-field.css';
```

### Javascript Instantiation

React Text Field accepts one child element which is the input element. For ease of integration, we have provided an input component to be used with React Text Field.

```js
import React from 'react';
import TextField, {HelperText, Input} from '@material/react-text-field';

class MyApp extends React.Component {
  state = {value: 'Woof'};

  render() {
    return (
      <div>
        <TextField
          label='Dog'
          helperText={<HelperText>Help Me!</HelperText>}
        >
          <Input
            value={this.state.value}
            onChange={(e) => this.setState({value: e.target.value})}/>
        </TextField>
      </div>
    );
  }
}
```

> NOTE: In order to get access to the value, you must add an onChange handler, which accepts an event and updates the value of the input as shown above.
## Props

Prop Name | Type | Description
--- | --- | ---
children | Element | Mandatory. The input element of the text field.
className | String | An optional class added to the `.mdc-text-field` element.
dense | Boolean | Enables dense variant.
floatingLabelClassName | String | An optional class added to the floating label element of the text field.
fullWidth | Boolean | Enables fullWidth variant.
helperText | Element | Helper text that appears below the text field. Use the `<HelperText>` component that comes with this package.
isRtl | Boolean | Whether the direction of the text field element is set to RTL.
label | String | Mandatory. Label text that appears as the floating label or placeholder.
leadingIcon | Element | An icon element that appears as the leading icon.
lineRippleClassName | String | An optional class added to the line ripple element.
notchedOutlineClassName | String | An optional class added to the notched outline element.
outlined | Boolean | Enables outlined variant.
textarea | Boolean | Enables textarea variant.
trailingIcon | Element | An icon element that appears as the trailing icon.

### Input Props

Not all the props below are used for majority of cases. Properties like `foundation` shouldn't be used when implementing the text field, but is used internally in React Text Field.

Prop Name | Type | Description
--- | --- | ---
inputType | string | HTML tag to be used to render input element. 'input' (default) or 'textarea'.
className | String | Classes to be applied to the input element.
disabled | Function | Disables the input and the parent text field.
foundation | Function | The text field foundation.
handleValueChange | Function | A callback function to update React Text Field's value.
isValid | Boolean | If set, this value will override the native input's validation.
id | String | The `<input>` id attribute.
onBlur | Function | Blur event handler.
onChange | Function | Change event handler.
onFocus | Function | Focus event handler.
onMouseDown | Function | Mouse down event handler.
onTouchStart | Function | Touch start event handler.
setDisabled | Function | Callback function that is called when the `disabled` prop updates.
setInputId | Function | Callback function that is called when the `id` attribute updates.
handleFocusChange | Function | Callback function that is called when `focus` or `blur` events occur
value | Number/String | Value of the input.
ref | Function(input: ReactElement) => void | On mount of component, will call passed function with the instance of the `<Input />`.

>NOTE: the `<Input>` component will receive all properties that a standard `<input>` accepts.

### Accessing the Native Input element

There will be times when you need to access the native <input />. For example if you need to focus the text field, you can add a ref callback method to the `<Input />` element and access the `<input />`. The `ref` will accept a callback method and on mount and will pass the instance of the input component. Here is an example of how to programatically focus the `<input />`:

```js
import React from 'react';
import TextField, {Input} from '@material/react-text-field';
import Button from '@material/react-button';

class MyApp extends React.Component {
  input = null;
  state = {value: 'Woof'};

  focusTextField = () => {
    if (!this.input) return;
    const inputElement = this.input.inputElement;
    if (inputElement) {
      inputElement.focus();
    }
  }

  render() {
    return (
      <div>
        <div>
          <Button onClick={this.focusTextField}>Focus Text Field</Button>
        </div>
        <TextField label='Dog'>
          <Input
            value={this.state.value}
            ref={input => this.input = input}
            onChange={(e) => this.setState({value: e.target.value})}/>
        </TextField>
      </div>
    );
  }
}
```


### Sass Mixins

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.

[Advanced Sass Mixins](https://github.com/material-components/material-components-web/blob/master/packages/mdc-textfield/README.md)

## Usage with Icons

Please see our [Best Practices doc](../../docs/best-practices.md#importing-font-icons) when importing or using icon fonts.

---
_Source: https://npm.io/package/closure-react-text-field · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
