Skip to content

Bug: Clicking file input label that's rendered in the list changes onChange handler behavior(to non-react behavior) #27007

@gadishimwe

Description

@gadishimwe

I'm using a file input rendered in the list and somehow onChange handler of one (the first in CodeSandbox example) item is being used for the rest items in the list as their onChange handler when I click the label instead of the input (because I'm planning to hide it later).

React version:
18.2.0

Steps To Reproduce

  1. Map over any list and render a file input with a label.
  2. Console.log() the index from the map in the onChange handler.
  3. Click the label of any item in the list, not the actual input. It should log 0 for all items. It should work normally as usual if you click input though.

(U can use the CodeSandbox below. These steps are already implemented)

Link to code example:

https://codesandbox.io/s/modern-firefly-8qm4ws?file=/src/App.tsx

Check the console.

The current behavior

One onChange handler is being used for all items in the list when I use a label to trigger input change.

The expected behavior

Every item (input) should have a unique onChange handler as usual in React.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions