Skip to content

NumberField: onBlur event always resets invalidation #9444

@HugoKNL

Description

@HugoKNL

Provide a general summary of the issue here

We use zod schema validation for our forms and use the NumberField component within our forms. The validation happens onSubmit and on an object built like this: Object.fromEntries(new FormData(e.currentTarget))

What we observe with all React Aria Components, is that the onBlur event checks wether the field is "dirty", and if so, the component removes the [data-invalid] attribute. The number field acts different, it always removes the [data-invalid] attribute "onBlur", because it seems to think the value is "dirty" even when the value hasn't changed.

🤔 Expected Behavior?

Only remove the [data-invalid] attribute "onBlur" when value is dirty.

😯 Current Behavior

Remove [data-invalid] attribute on any "onBlur" event. (even if field is not dirty).

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

      <Form
            validationErrors={{testNumber: "foo-bar error!"}}
      >
            <NumberField name="testNumber">
                 <Label>Test Number</Label>
                 <Input />
                 <FieldError />
            </NumberField>
            <Button type="submit" />
      </Form>
  1. Put the above in a react page, type something in the number field (i.e. "1") and press submit.
  2. See the error occur.
  3. Focus the number field
  4. Blur the number field
  5. See the error dissapear

Version

1.13.0

What browsers are you seeing the problem on?

Microsoft Edge

If other, please specify.

also on FireFox and Chrome

What operating system are you using?

Windows 11

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions