Skip to content

Commit

Permalink
fix(Forms): show indicator with async onBlurValidator call when `vali…
Browse files Browse the repository at this point in the history
…dateInitially` is used
  • Loading branch information
tujoworker committed Nov 20, 2024
1 parent 69bbdaf commit 8a5b263
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4408,6 +4408,10 @@ describe('useFieldProps', () => {
</Form.Handler>
)

expect(
document.querySelector('.dnb-forms-submit-indicator')
).toHaveClass('dnb-forms-submit-indicator--state-pending')

await waitFor(() => {
expect(screen.queryByRole('alert')).toBeInTheDocument()
})
Expand Down Expand Up @@ -4581,7 +4585,7 @@ describe('useFieldProps', () => {
})

describe('validateInitially', () => {
it('should not show error message initially', async () => {
it('should show error message initially', async () => {
const validator = jest.fn(validatorFn)

render(
Expand All @@ -4597,7 +4601,9 @@ describe('useFieldProps', () => {
</Form.Handler>
)

expect(screen.queryByRole('alert')).not.toBeInTheDocument()
await waitFor(() => {
expect(screen.queryByRole('alert')).toBeInTheDocument()
})
})

it('should not show error message while typing', async () => {
Expand All @@ -4620,7 +4626,7 @@ describe('useFieldProps', () => {
document.querySelectorAll('input')
)

expect(screen.queryByRole('alert')).not.toBeInTheDocument()
expect(screen.queryByRole('alert')).toBeInTheDocument()

await userEvent.type(inputWithRefValue, '{Backspace}')

Expand Down Expand Up @@ -4680,9 +4686,7 @@ describe('useFieldProps', () => {

await userEvent.type(inputWithRefValue, '3')

await waitFor(() => {
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
})
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ export default function useFieldProps<Value, EmptyValue, Props>(
}

revealOnBlurValidatorResult({ result })

return { result }
},
[
asyncBehaviorIsEnabled,
Expand Down Expand Up @@ -1114,7 +1116,7 @@ export default function useFieldProps<Value, EmptyValue, Props>(
validateInitially &&
!changedRef.current
) {
const { result } = await callOnBlurValidator()
const { result } = await startOnBlurValidatorProcess()

if (result instanceof Error) {
initiator = 'onBlurValidator'
Expand All @@ -1133,7 +1135,6 @@ export default function useFieldProps<Value, EmptyValue, Props>(
}
}
}, [
callOnBlurValidator,
clearErrorState,
disabled,
emptyValue,
Expand All @@ -1143,6 +1144,7 @@ export default function useFieldProps<Value, EmptyValue, Props>(
required,
requiredProp,
setFieldState,
startOnBlurValidatorProcess,
startOnChangeValidatorValidation,
startProcess,
validateInitially,
Expand Down

0 comments on commit 8a5b263

Please sign in to comment.