New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: break out of all loops on first focus #11827
base: master
Are you sure you want to change the base?
Fix: break out of all loops on first focus #11827
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
1242d57
to
08913e3
Compare
it('should focus on the first error it encounter and not the second', () => { | ||
const focus = jest.fn(); | ||
iterateFieldsByAction( | ||
{ | ||
first: { | ||
_f: { | ||
name: 'first', | ||
ref: { | ||
name: 'first', | ||
focus, | ||
}, | ||
}, | ||
}, | ||
second: { | ||
_f: { | ||
name: 'second', | ||
ref: { | ||
name: 'second', | ||
focus, | ||
}, | ||
}, | ||
}, | ||
}, | ||
(ref) => { | ||
// @ts-ignore | ||
ref.focus && ref.focus(ref.name); | ||
return 1; | ||
}, | ||
); | ||
expect(focus).toBeCalledWith('first'); | ||
expect(focus).not.toBeCalledWith('second'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existing logic pass this test as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure the fix here, i thought the existing logic to break early as well
); | ||
expect(focus).not.toBeCalledWith('first'); | ||
expect(focus).toBeCalledWith('last'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existing logic pass this test as well.
I have a form structure like so, where I have a group depth of more than 2.
What was happening is when
iterateFieldsByAction
calls itself recursively it did call focus onpersonal.name.first
but then it breaks out ofpersonal.name
and continues looping and calling focus onpersonal.phone-number
.This change will break out of the current loop and recursively break out of all loops.