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

feat(InputFile): multipleでファイルを追加していけるように変更 #5281

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Qs-F
Copy link
Contributor

@Qs-F Qs-F commented Jan 15, 2025

関連URL

概要

InputFileでmultipleのときにファイルを追加していけるようにした

変更内容

  • InputFileでmultipleのときにファイルを追加していけるようにした

確認方法

以下をsandbox内などにおき試してみる

<form
  onSubmit={
    (e) => {
      e.preventDefault()
      const formData = new FormData(e.currentTarget)
      console.log(formData.getAll('files'))
    }
  }
>
  <InputFile multiple label="Files" name="files" />
  <button type="submit">submit</button>
</form>

@Qs-F Qs-F changed the title feat(InputFile): multipleのときにファイルを追加していけるように修正 feat(InputFile): multipleのときにファイルを追加していけるように変更 Jan 15, 2025
@Qs-F Qs-F changed the title feat(InputFile): multipleのときにファイルを追加していけるように変更 feat(InputFile): multipleでファイルを追加していけるように変更 Jan 15, 2025
Copy link

pkg-pr-new bot commented Jan 15, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5281

commit: 192d1e5

@Qs-F Qs-F marked this pull request as ready for review January 30, 2025 10:21
@Qs-F Qs-F requested a review from a team as a code owner January 30, 2025 10:21
@Qs-F Qs-F requested review from yt-ymmt and yuzuru-akiyama and removed request for a team January 30, 2025 10:21
@Qs-F Qs-F marked this pull request as draft January 30, 2025 10:25
@Qs-F Qs-F marked this pull request as ready for review January 30, 2025 10:25
@Qs-F Qs-F requested review from AtsushiM and uknmr and removed request for yt-ymmt and yuzuru-akiyama January 30, 2025 10:25
@Qs-F
Copy link
Contributor Author

Qs-F commented Jan 30, 2025

メモ: レビューしやすいように変更を最小限にした


if (multiple) {
// multipleの場合、すでに選択済みのファイルと結合する
updateFiles([...files, ...newFiles])
Copy link
Member

@AtsushiM AtsushiM Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この仕様は議論の余地がありそう。
Chromeなどのブラウザ実装では

  • 一度目に選んだファイルは、二度目に選ばれたファイル群と結合されない

つまりイメージとしては都度渡された配列を結合するのではなく、常に上書きされます。
個人的にはmultipleを実装するならブラウザデフォルトの動きに合わせたいです。
もしユースケースとして結合させたい場合があるなら、属性名はmultiple以外にしたいです(最終的にinput[file][multiple]が出力されるとしても、デフォルトではない挙動をするなら、コンポーネントとしての属性は別の名前
にしておいたほうが事故はすくなるなるかと...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどです!ユースケース的にはこの挙動自体は以前定例で話した通り、他のプロダクトでもある認識です〜
props名はたしかに感あるので、 multiple & appendable のときにこの挙動をする、とかだとどうでしょう?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

↑良さそう
ただ実際問題として multiple だけで設定することがないような気がする...
雑ですが multiAppendable みたいな1属性で設定してもいいかもですね...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants