You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Observe that the input displays "0" as the initial value on the first render.
Click into the <NumericInput> field to see the correct/expected value appear.
Expected behavior
The floating-point value should display accurately on the initial render without user interaction.
Actual behavior
On initial render, the floating-point value is truncated or rounded to "0".
Explanation
The issue seems to originate from the roundAndClampValue logic called in the getDerivedStateFromProps() lifecycle method. By default, stepMaxPrecision is set to 1, causing toMaxPrecision to round the floating-point value to "0".
The first time getDerivedStateFromProps is executed, the sanitized value is set as value in the component state. On subsequent executions of getDerivedStateFromProps, didBoundsChange evaluates to false, which causes the original value from props, e.g. "2.7E-10", to be set in the component state. This is why we see the correct value get displayed only after clicking into the field.
Also, conversely, this behavior does not occur if min or max is not set, precisely because didBoundsChange evaluates to false on initial render (and thus the sanitization behavior is not executed on the value from props).
Possible solution
A very hacky workaround for this issue would be to force an additional update on initial mount:
publiccomponentDidMount(){this.forceUpdate();}
However, this seems very suboptimal. A better solution might require us correctly determining the step max precision based on the original value from props in addition to minorStepSize .
The text was updated successfully, but these errors were encountered:
Environment
v5.16.4
Chrome 132.0.6834.111
Code Sandbox
https://codesandbox.io/p/sandbox/lm7rdk?file=%2Fsrc%2FExample.tsx
Steps to reproduce
<NumericInput>
component with:value
(e.g.,"0.001"
or"2.7E-10"
).min
ormax
value set, for example:<NumericInput>
field to see the correct/expected value appear.Expected behavior
The floating-point value should display accurately on the initial render without user interaction.
Actual behavior
On initial render, the floating-point value is truncated or rounded to "0".
Explanation
The issue seems to originate from the
roundAndClampValue
logic called in thegetDerivedStateFromProps()
lifecycle method. By default,stepMaxPrecision
is set to1
, causingtoMaxPrecision
to round the floating-point value to "0".blueprint/packages/core/src/components/forms/numericInput.tsx
Line 249 in 5d092cd
blueprint/packages/core/src/components/forms/numericInput.tsx
Lines 274 to 289 in 5d092cd
blueprint/packages/core/src/components/forms/numericInputUtils.ts
Lines 148 to 160 in 5d092cd
The first time
getDerivedStateFromProps
is executed, the sanitized value is set asvalue
in the component state. On subsequent executions ofgetDerivedStateFromProps
,didBoundsChange
evaluates tofalse
, which causes the original value from props, e.g. "2.7E-10", to be set in the component state. This is why we see the correct value get displayed only after clicking into the field.Also, conversely, this behavior does not occur if
min
ormax
is not set, precisely becausedidBoundsChange
evaluates tofalse
on initial render (and thus the sanitization behavior is not executed on the value from props).Possible solution
A very hacky workaround for this issue would be to force an additional update on initial mount:
However, this seems very suboptimal. A better solution might require us correctly determining the step max precision based on the original
value
from props in addition tominorStepSize
.The text was updated successfully, but these errors were encountered: