Skip to content

Commit 885f98a

Browse files
authored
Deduce select type from component prop for select-multiple (#793)
* Deduce select type from component prop for select-multiple * Added build script to please codesandbox CI * Updated node versions in travis config
1 parent 573e414 commit 885f98a

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ cache:
88
notifications:
99
email: false
1010
node_js:
11-
- '8'
1211
- '10'
13-
- '11'
12+
- '12'
13+
- '14'
1414
script:
1515
- npm start validate
1616
after_success:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"start": "nps",
1616
"test": "nps test",
1717
"precommit": "lint-staged && npm start validate",
18+
"build": "npm start build",
1819
"prepublish": "npm start validate"
1920
},
2021
"author": "Erik Rasmussen <[email protected]> (http://github.com/erikras)",

src/Field.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,14 @@ describe('Field', () => {
996996
</select>
997997
)}
998998
</Field>
999+
<Field
1000+
name="selectMultipleWithoutRenderProp"
1001+
component="select"
1002+
data-testid="selectMultipleWithoutRenderProp"
1003+
multiple
1004+
>
1005+
<option>{'Option'}</option>
1006+
</Field>
9991007
</form>
10001008
)}
10011009
</Form>
@@ -1026,6 +1034,11 @@ describe('Field', () => {
10261034
'You must pass `type="select"` prop to your Field(selectMultipleInput) component.\n' +
10271035
"Without it we don't know how to unpack your `value` prop - []."
10281036
)
1037+
fireEvent.change(getByTestId('selectMultipleWithoutRenderProp'), {
1038+
target: { value: ['some value'] }
1039+
})
1040+
// error not given, since we can deduce that it's a "select"
1041+
expect(errorSpy).toHaveBeenCalledTimes(3)
10291042
errorSpy.mockRestore()
10301043
})
10311044

src/useField.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ function useField<FormValues: FormValuesShape>(
156156
const targetType = event.target.type
157157
const unknown =
158158
~['checkbox', 'radio', 'select-multiple'].indexOf(targetType) &&
159-
!type
159+
!type &&
160+
component !== 'select'
160161

161162
const value: any =
162163
targetType === 'select-multiple' ? state.value : _value

0 commit comments

Comments
 (0)