reactjs / reactjs/react.dev

Weird troubleshooting info for controlled inputs?

オープン
#6,237 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

Hi team! 👋

During our translation work I came across a weird bit of troubleshooting advice on the <textarea> page.

Quite expectedly, it's also found in the <input> page.

It basically states that setting the controlling state variable to anything other than the raw e.target.value (e.g. transforming it to uppercase, used to illustrate the "bug", only it works just fine) is the cause for the caret jumping back to the beginning.

This seems misleading and borderline incorrect; one of the key benefits of controlled inputs is our ability to format / filter / validate values live (think phone numbers, SSNs, CC numbers, VAT identifiers, etc.) and this only moves the caret back when the resulting value is shorter. It doesn't reset it to the beginning.

Here's a CodeSandbox demonstrating things are just fine for many use-cases of setting the controlled value to a transformed version of the incoming DOM value.

Any light on this? What are the actually problematic patterns for caret jumping?

Best,

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

React DOM input と textarea のリファレンスページにあるリンク先のトラブルシューティングセクションから始め、提供された CodeSandbox でその動作を再現します。変換された制御値を、キャレットが移動するという文書化されたシナリオと比較します。完了の条件は、どのような値の更新パターンがキャレットの移動を引き起こすのかをドキュメントが正確に説明し、有効なフォーマットのユースケースを誤解を招く例として示さなくなることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。