Skip to content

Bug: onChange event is fired twice when replacing selected text #20476

@perenstrom

Description

@perenstrom

React version: 17.0.1

Steps To Reproduce

  1. Add an onChange handler to an input[type=text] field, logging the event.target.value
  2. Write a letter in the input (see that it fires an event)
  3. Select all text
  4. Type a new letter, thus replacing the previous letter
  5. This will trigger two events on some device setups, one with blank input, and one with the new letter.

Link to code example: https://codesandbox.io/s/react-input-event-twice-4dh59

The current behavior

On some devices the replacement of a selection fires twice, first with empty input and second with the typed letter.

mobile-chrome-onchange

The expected behavior

Only one input event should be fired, with the new letter.

Screenshot 2020-12-16 at 20 40 58

Devices/browsers tested:

Two events (bug):

  • OnePlus 5, Android OxygenOS 9.0.9, Chrome 87.0.4280.101
  • OnePlus 3T, Android OxygenOS 9.0.6, Chrome 87.0.4280.101

One events (working as intended):

  • MacOS 10.14.6, Firefox 83.0
  • MacOS 10.14.6, Chrome 87.0.4280.88
  • iPhone X, iOS 14.2, Chrome 87.0.4280.77
  • Pixel 2, Android 8.0.0, Chrome 87.0.4280.101 (however this test person experienced the bug earlier, but might have been an in app browser somewhere)

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions