Skip to content

Commit e0d2442

Browse files
pzupanAlmouro
authored andcommitted
feat(withNextInputAutoFocusForm): allow disabling of automatic form submit
The last input withNextInputAutoFocus establishes that the input is the last and then submits. This adds a new parameter to disable autosubmit.
1 parent 3462fb7 commit e0d2442

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/withNextInputAutoFocus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const getInputs = children =>
1818
return partialInputs;
1919
}, []);
2020

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

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

4545
if (isLastInput) {
46-
this.props.formik.submitForm();
46+
if (submitAfterLastInput) this.props.formik.submitForm();
4747
} else {
4848
const nextInputs = this.inputs.slice(inputPosition + 1);
4949
const nextFocusableInput = nextInputs.find(

0 commit comments

Comments
 (0)