Skip to content

Commit

Permalink
feat(withNextInputAutoFocusForm): allow disabling of automatic form …
Browse files Browse the repository at this point in the history
…submit

The last input withNextInputAutoFocus establishes that the input is the last and then submits.  This adds a new parameter to disable autosubmit.
  • Loading branch information
pzupan authored and Almouro committed Dec 10, 2018
1 parent 3462fb7 commit e0d2442
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/withNextInputAutoFocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getInputs = children =>
return partialInputs;
}, []);

export const withNextInputAutoFocusForm = WrappedComponent => {
export const withNextInputAutoFocusForm = (WrappedComponent, { submitAfterLastInput } = { submitAfterLastInput: true }) => {
class WithNextInputAutoFocusForm extends React.PureComponent {
static childContextTypes = withNextInputAutoFocusContextType;

Expand All @@ -43,7 +43,7 @@ export const withNextInputAutoFocusForm = WrappedComponent => {
const isLastInput = inputPosition === this.inputs.length - 1;

if (isLastInput) {
this.props.formik.submitForm();
if (submitAfterLastInput) this.props.formik.submitForm();
} else {
const nextInputs = this.inputs.slice(inputPosition + 1);
const nextFocusableInput = nextInputs.find(
Expand Down

0 comments on commit e0d2442

Please sign in to comment.