1
1
import React , { useCallback } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { normalizeOptions , normalizeDisabled } from './helpers/form-helpers' ;
4
- import { useFormControl } from './helpers/useFormControl' ;
3
+
5
4
import { getValueByPath } from '../utils/getters-setters' ;
5
+ import { normalizeOptions , booleanOrFunction } from './helpers/form-helpers' ;
6
+ import { useFormControl } from './helpers/useFormControl' ;
6
7
7
- export function FormSelect ( { id, name, options, required, placeholder, trackBy, disabled : _disabled } ) {
8
+ export function FormSelect ( { id, name, options, required : _required , placeholder, trackBy, disabled : _disabled } ) {
8
9
const { getFormData, getValue, handleOnChange, register } = useFormControl ( name ) ;
9
10
const registerRef = useCallback ( register , [ register ] ) ;
10
11
const value = getValue ( ) ;
11
12
const normalizedOptions = normalizeOptions ( options , getFormData ( ) ) ;
12
- const disabled = normalizeDisabled ( _disabled , getFormData ( ) ) ;
13
+ const disabled = booleanOrFunction ( _disabled , getFormData ( ) ) ;
14
+ const required = booleanOrFunction ( _required , getFormData ( ) ) ;
13
15
14
16
return (
15
17
< select
@@ -34,7 +36,7 @@ FormSelect.propTypes = {
34
36
PropTypes . arrayOf ( PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ) ,
35
37
] ) ,
36
38
placeholder : PropTypes . string ,
37
- required : PropTypes . bool ,
39
+ required : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
38
40
trackBy : PropTypes . string ,
39
41
disabled : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
40
42
} ;
0 commit comments