Skip to content

Fix: Support type='select' for multiple select defaulting to []#1061

Open
erikras-richard-agent wants to merge 1 commit intomainfrom
fix/select-multiple-type-prop
Open

Fix: Support type='select' for multiple select defaulting to []#1061
erikras-richard-agent wants to merge 1 commit intomainfrom
fix/select-multiple-type-prop

Conversation

@erikras-richard-agent
Copy link
Contributor

@erikras-richard-agent erikras-richard-agent commented Feb 4, 2026

Problem

React-final-form-arrays issue #185 reported this error after upgrading to v4.0.0:

The \`value\` prop supplied to <select> must be an array if \`multiple\` is true.

When users pass type="select" multiple={true} to a Field, the value wasn't being defaulted to [], causing React to complain.

Root Cause

The code in useField.ts only checked component === "select" to determine when to default undefined values to []. However, many users pass type="select" instead of component="select".

Solution

Update both locations where select multiple is handled:

  1. Line 125: Initialize undefined values to [] when (component === "select" || type === "select") && multiple
  2. Line 197: Ensure value is always an array in getInputValue() when (component === "select" || type === "select") && multiple

Testing

  • ✅ Added 3 new regression tests
  • ✅ All tests pass (139/139)
  • ✅ 99.32% code coverage

Part of

🟠 HIGH: Fix v4.0.0 regressions (select multiple, TypeScript)

This fixes the react-final-form side of react-final-form-arrays#185

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced multi-select form field handling to properly initialize with empty arrays instead of undefined values, ensuring consistent behavior across different select element configurations.
  • Tests

    • Added comprehensive test coverage for multi-select form field scenarios, validating proper initialization and input value handling for select elements with multiple selection states.

- Previously only component='select' was checked for multiple select handling
- Now also checks type='select' to match user expectations
- Fixes react-final-form-arrays#185 where users pass type='select' multiple
- Added 3 regression tests to verify fix
- All tests pass (139/139, 99.32% coverage)
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This pull request extends the multi-select handling logic in useField to recognize both type="select" and component="select" attributes, ensuring that undefined initial values consistently default to empty arrays for multi-select scenarios. The changes include corresponding test cases validating both patterns.

Changes

Cohort / File(s) Summary
Test Suite
src/useField.test.js
Adds three new test cases for multi-select scenarios: validates that undefined values default to [] when using type="select" with multiple, validates the same for component="select" with multiple, and ensures input.value is always an array for select multiple cases.
Core Logic
src/useField.ts
Extends multi-select initialization and value resolution to check for both type="select" and component="select", ensuring initialStateValue and rendered values use empty arrays when multiple is true and initial value is undefined.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • erikras

Poem

🐰 A select with multiple? Oh what a sight!
Type or component, we handle both right,
When undefined knocks, we say "No way, friend!"
An empty array's the proper amend! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding support for type='select' in multiple select scenarios with proper [] defaulting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/select-multiple-type-prop

Comment @coderabbitai help to get the list of available commands and usage tips.

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