Skip to content

Fix controlled numberfield blur shows old value quickly #2882

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

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@react-stately/numberfield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
},
"dependencies": {
"@babel/runtime": "^7.6.2",
"@internationalized/number": "^3.0.5",
"@react-aria/utils": "^3.11.2",
"@react-stately/utils": "^3.4.1",
"@react-types/numberfield": "^3.1.2",
"@react-types/shared": "^3.11.1",
"@internationalized/number": "^3.0.5"
"@react-types/shared": "^3.11.1"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0-rc.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import {clamp, snapValueToStep, useControlledState} from '@react-stately/utils';
import {NumberFieldProps} from '@react-types/numberfield';
import {NumberFormatter, NumberParser} from '@internationalized/number';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {useCallback, useMemo, useRef, useState} from 'react';
import {useLayoutEffect} from '@react-aria/utils';

export interface NumberFieldState {
/**
Expand Down Expand Up @@ -104,7 +105,7 @@ export function useNumberFieldState(
// Update the input value when the number value or format options change. This is done
// in a useEffect so that the controlled behavior is correct and we only update the
// textfield after prop changes.
useEffect(() => {
useLayoutEffect(() => {
setInputValue(format(numberValue));
}, [numberValue, locale, formatOptions]);

Expand Down