Chakra-ui: [NumberInput] A component is changing an uncontrolled input of type text to be controlled

Created on 3 Dec 2019  路  3Comments  路  Source: chakra-ui/chakra-ui

Describe the bug
When using intentionally null value for a NumberInput, the component crashes with the stack trace below:

index.js:2177 Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components
    in input (created by Context.Consumer)
    in PseudoBox (created by Input)
    in Input (created by NumberInputField)
    in NumberInputField (at NumericEvaluator.tsx:72)
    in div (created by Context.Consumer)
    in Box (created by Flex)
    in Flex (created by NumberInput)
    in NumberInput (at NumericEvaluator.tsx:57)

Expected Behavior
NumberInput.value should be given null without issues.

Most helpful comment

@aaronmcadam, yeah I'm aware.

It's related to a PR from @kripod I merged a while ago. I'll release a patch for it shortly.

All 3 comments

I've run into this a few times over the past few days. Do you have any thoughts on this one @segunadebayo?

@aaronmcadam, yeah I'm aware.

It's related to a PR from @kripod I merged a while ago. I'll release a patch for it shortly.

I've fixed this issue and will publish a patch shortly.

As it stands, NumberInput can't be given a null value as it's not allowed by default in input fields. To support that scenario, we'll have to break the controlled/uncontrolled switching rule of React and I don't think it's worth it.

NumberInput returns a string | number depending on the current state of the value. To denote the absence of a value, use an empty string "".

I'll release a patch in a couple of hours.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harshzalavadiya picture harshzalavadiya  路  3Comments

rovervannispen picture rovervannispen  路  3Comments

elmeerr picture elmeerr  路  3Comments

kripod picture kripod  路  3Comments

callumflack picture callumflack  路  3Comments