react / react/react-native

Uncontrolled input value clears when color is changed

未关闭
#43,403 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue: Author Provided Repro
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

Setting color in style prop for an uncontrolled input based on focus clears the TextInput's value.
example:

...
    <TextInput
      onBlur={onBlur}
      onFocus={onFocus}
      placeholder={placeholder}
      style={[
        {
          color: isFocused ? "#f00" : "#000",
        },
      ]}
    />
...

isFocused is set based on onBlur and onFocus.

This same issue is not noticed for a controlled input. I have also linked a repro link with both cases side by side.

Affected platform: Android

Steps to reproduce
  1. Run the application with npx react-native run-android
  2. Interact with controlled input (notice normal behaviour)
  3. Interact with uncontrolled input, notice value of input disappearing when you blur the focus
React Native Version

0.73.5

Affected Platforms

Runtime - Android

Output of npx react-native info
System:
  OS: macOS 14.2.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 179.17 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.1
    path: ~/.nvm/versions/node/v18.19.1/bin/node
  Yarn:
    version: 1.22.21
    path: ~/.bun/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v18.19.1/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.5
    wanted: 0.73.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
N/A
Reproducer

https://github.com/BalogunofAfrica/react-native-textinput-bug

Screenshots and Videos

https://github.com/facebook/react-native/assets/45393944/91a05b3e-06c1-4ca5-ac39-74d0da2522d7

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 reproducer 开始,并在 React Native 0.73.5 上使用 npx react-native run-android 运行它。在更改基于 focus 的颜色时,对比受控和非受控的 TextInput 情况;当非受控输入框在失去 focus 后保留其值,且受控情况不受影响时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
react-native
领域
mobile
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。