# multi-input-input

> Modifies a component that contains multiple inputs to behave as though it was a single input

Latest version **0.0.3** (published 2018-09-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install multi-input-input
pnpm add multi-input-input
yarn add multi-input-input
bun add multi-input-input
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2018-09-19 |
| First published | 2018-09-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alasdair McLeay |
| Maintainers | penx |

## Links

- npm: https://www.npmjs.com/package/multi-input-input
- Repository: https://github.com/penx/multi-input-input
- Homepage: https://github.com/penx/multi-input-input#readme
- Issues: https://github.com/penx/multi-input-input/issues
- npm.io page: https://npm.io/package/multi-input-input

## Recent versions

- 0.0.3 (latest) — 2018-09-19
- 0.0.2 — 2018-09-19
- 0.0.1 — 2018-09-19

## README

# Multi Input Input

A React higher order component that modifies a given component containing multiple inputs to behave as though it was a single input by:
- merging values in to an object
- not calling onBlur when going from field to field within the same component
- not calling onFocus when going from field to field within the same component

# Why?

See
https://medium.com/@penx/form-elements-in-presentational-component-packages-a618e9aa7416

# Usage:

For example, 3 inputs could be combined to form a single date input:

```jsx
import React from 'react';
import PropTypes from 'prop-types';

import multiInputInput from '../../hoc/multiInputInput';

class OptionalDateInput extends React.Component {
  inputs = {}

  renderInput(label, key) {
    return (
      <label>
        {label}:
        <input
          value={(this.props.value && this.props.value[key]) || ''}
          onChange={e => this.props.onChange(e, key)}
          onBlur={e => this.props.onBlur(e, key)}
          onFocus={e => this.props.onFocus(e, key)}
          ref={(input) => { this.inputs[key] = input; this.props.refs(this.inputs); }}
        />
      </label>);
  }

  render() {
    return (
      <div>
        {this.renderInput('Day', 'day')}
        {this.renderInput('Month', 'month')}
        {this.renderInput('Year', 'year')}
      </div>
    );
  }
}

OptionalDateInput.propTypes = {
  value: PropTypes.shape({
    day: PropTypes.number,
    month: PropTypes.number,
    year: PropTypes.number,
  }),
  refs: PropTypes.func,
  onChange: PropTypes.func,
  onBlur: PropTypes.func,
  onFocus: PropTypes.func,
};

OptionalDateInput.defaultProps = {
  value: {
    day: null,
    month: null,
    year: null,
  },
  refs: () => null,
  onChange: () => null,
  onBlur: () => null,
  onFocus: () => null,
};

// This component is dependent on multiInputInput HOC so we always export with HOC
export default multiInputInput(OptionalDateInput);
```


See https://github.com/penx/pcp-form-example/blob/master/packages/presentational-components/src/components/input/OptionalDateInput.js

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