Skip to content

Commit 1ebb0fe

Browse files
authored
Fix: Wrap commit() in flushSync on Enter in useNumberField When Enter is pressed in NumberField, commit() was called without flushSync, unlike the blur handler which wraps commit() in flushSync. This caused controlled form libraries reading React state immediately after Enter to receive stale values instead of the committed value. The browser synthesizes a trusted click on the form's submit button when Enter is pressed, firing onSubmit before the unguarded commit() has flushed to React state. This change wraps commit() in flushSync on Enter, making it consistent with the blur behavior and ensuring the value is flushed synchronously before any consumer reads form state. Fixes adobe#9671 (adobe#9683)
1 parent 3a5d7d8 commit 1ebb0fe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/@react-aria/numberfield/src/useNumberField.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
219219
}
220220

221221
if (e.key === 'Enter') {
222-
commit();
222+
flushSync(() => {
223+
commit();
224+
});
223225
commitValidation();
224226
} else {
225227
e.continuePropagation();

0 commit comments

Comments
 (0)