nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Bug when input type is file.

Open vikramsamak opened this issue 1 year ago • 4 comments

NextUI Version

2.2.9

Describe the bug

When using the input component with file type, I observed that on the first click to choose a file, the selected file is logged as "undefined" in the console. However, on the second attempt, the correct file information is logged

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Click the "Choose File" button to open the file dialog. On the first click, notice that the selected file is logged as "undefined" in the console. On the second click, the correct file information is logged.

Expected behavior

The file input value should be cleared consistently on each click to ensure that the correct file information is logged on the first attempt.

Screenshots or Videos

https://github.com/nextui-org/nextui/assets/95061742/e210cb3e-c389-49ec-99b6-469d68d7a86b

Operating System Version

windows 11

Browser

Edge

vikramsamak avatar Feb 03 '24 12:02 vikramsamak

Same here, any solutions?

AustinZhu avatar Feb 15 '24 06:02 AustinZhu

I am experiencing the same issue. For now, I am using a regular input element and styled it the same.

johnjjimenez avatar Mar 16 '24 00:03 johnjjimenez

Same issue in 2.2.10

Ishov avatar Mar 22 '24 07:03 Ishov

same issue in v2.3.6

HustCoderHu avatar May 08 '24 05:05 HustCoderHu

This seems to be an issue since value="" is set on the input element that NextUI creates. It looks like value="" is assumed to be the default which isn't true for inputs with type=file. In use-input.ts, an empty string is always assumed to be the default value an input should be.

If I force value to be null, the file input works as expected:

<Input
    {...rest}
    // @ts-expect-error -- Known issue with NextUI's Input component
    defaultValue={null}
    multiple={allowMultiple}
    onChange={handleChange}
    type="file"
    // @ts-expect-error -- Known issue with NextUI's Input component
    value={null}
/>

Don't actually do the above in production, it does give a warning that values should not be null, they should be undefined for uncontrolled components. This is just to demonstrate that the empty string appears to be the issue.

There are some related tickets to this issue in the issue tracker:

  • https://github.com/nextui-org/nextui/issues/2965
  • https://github.com/nextui-org/nextui/issues/2397

idmontie avatar May 13 '24 21:05 idmontie