Skip to content
Prev Previous commit
Next Next commit
Mimic a stable server response time
  • Loading branch information
mirka committed Aug 20, 2025
commit 125b759816f6a1e2f945a02d198c27de628799e9
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,19 @@ export const AsyncValidation: StoryObj< typeof ValidatedInputControl > = {
} );

clearTimeout( timeoutRef.current );
timeoutRef.current = setTimeout(
() => {
if ( v?.toString().toLowerCase() === 'error' ) {
setCustomValidity( {
type: 'invalid',
message: 'The word "error" is not allowed.',
} );
} else {
setCustomValidity( {
type: 'valid',
message: 'Validated',
} );
}
},
// Mimics a random server response time.
// eslint-disable-next-line no-restricted-syntax
Math.random() < 0.5 ? 1500 : 300
);
timeoutRef.current = setTimeout( () => {
if ( v?.toString().toLowerCase() === 'error' ) {
setCustomValidity( {
type: 'invalid',
message: 'The word "error" is not allowed.',
} );
} else {
setCustomValidity( {
type: 'valid',
message: 'Validated',
} );
}
}, 1500 );
}, 500 ),
[]
);
Expand Down