Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Commit 6e49942

Browse files
committed
fix #33 text input issue
1 parent 38f98ad commit 6e49942

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ import * as React from 'react';
22
import { useFormContext } from 'react-hook-form';
33
import { Props, EventFunction } from './types';
44

5+
const isUndefined = (val: unknown): val is undefined => val === undefined;
6+
57
function getValue(target: any, { isCheckbox }: { isCheckbox: boolean }) {
68
// the following logic is specific for react-select
79
if (target && (Array.isArray(target) || (target.label && target.value))) {
810
return target;
911
}
12+
1013
return target
1114
? isCheckbox
1215
? target.checked
16+
: isUndefined(target.value)
17+
? target
1318
: target.value
14-
? target.value
15-
: target
1619
: target;
1720
}
1821

@@ -41,7 +44,7 @@ const RHFInput = ({
4144
const isOnChange = mode === 'onChange';
4245
const isOnBlur = mode === 'onBlur';
4346
const defaultData = isCheckbox
44-
? defaultChecked === undefined
47+
? isUndefined(defaultChecked)
4548
? false
4649
: defaultChecked
4750
: defaultValue;

0 commit comments

Comments
 (0)