Skip to content
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

[BUG] - Bug when input type is file. #2311

Closed
vikramsamak opened this issue Feb 3, 2024 · 6 comments · Fixed by #3268
Closed

[BUG] - Bug when input type is file. #2311

vikramsamak opened this issue Feb 3, 2024 · 6 comments · Fixed by #3268
Assignees
Labels
🐛 Type: Bug Something isn't working

Comments

@vikramsamak
Copy link

vikramsamak commented Feb 3, 2024

NextUI Version

2.2.9 2.4.1

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

INPUT-FILETYPE-ERROR-01.mp4

Operating System Version

windows 11

Browser

Edge

@vikramsamak vikramsamak added the 🐛 Type: Bug Something isn't working label Feb 3, 2024
@AustinZhu
Copy link

Same here, any solutions?

@johnjjimenez
Copy link

johnjjimenez commented Mar 16, 2024

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

@Ishov
Copy link

Ishov commented Mar 22, 2024

Same issue in 2.2.10

@HustCoderHu
Copy link

same issue in v2.3.6

@idmontie
Copy link

idmontie commented May 13, 2024

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:

@vikramsamak
Copy link
Author

Thanks for fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants