JedWatson / react-select

The Select Component for React.js
https://react-select.com/
MIT License
27.44k stars 4.1k forks source link

Pass form prop to input so it works even if the select is ouside the form tag #5782

Open zvin opened 8 months ago

zvin commented 8 months ago

Hello!

When using CreatableSelect outside of a form passing it a form prop, this prop is not passed to the created input resulting in the field not being submitted as part of the form. This PR fixes it.

My problem was with CreatableSelect but it might fix other use cases as well.

changeset-bot[bot] commented 8 months ago

🦋 Changeset detected

Latest commit: 0e43b00ce644ddf45bad8cc78124c2a20ec7a8d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------ | ----- | | react-select | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

codesandbox-ci[bot] commented 8 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0e43b00ce644ddf45bad8cc78124c2a20ec7a8d9:

Sandbox Source
react-codesandboxer-example Configuration
zvin commented 5 months ago

Using a regular select will submit the myField value.

<div>
  <form action="/someAction" id="myForm">
    <input type="submit" />
  </form>
  <select form="myForm" name="myField">
    <option value="x">X</option>
    <option value="y">Y</option>
  </select>
<div>

Using React-Select, it won't.

<div>
  <form action="/someAction" id="myForm">
    <input type="submit" />
  </form>
  <Select form="myForm" name="myField" options={[{ value:"x", label: "X" }, { value:"y", label: "Y" }]} />
<div>

This PR fixes it.