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:
import React from 'react';import PropTypes from 'prop-types'; import multiInputInput from '../../hoc/multiInputInput'; Component inputs = { return <label> label: <input = = = = = /> </label>; } { return <div> this this this </div> ; } OptionalDateInputpropTypes = value: PropTypes refs: PropTypesfunc onChange: PropTypesfunc onBlur: PropTypesfunc onFocus: PropTypesfunc; OptionalDateInputdefaultProps = value: day: null month: null year: null null null null null; // This component is dependent on multiInputInput HOC so we always export with HOCOptionalDateInput;