Skip to content

Commit

Permalink
🐞 fix react-hook-form#12021 issue with disable prop not reflect on re…
Browse files Browse the repository at this point in the history
…-render without trigger by useEffect (react-hook-form#12193)

* 🐞 fix react-hook-form#12021 issue with disable prop not reflect on re-render without trigger useEffect

* fix issue with unit tests
  • Loading branch information
bluebill1049 authored and oskarski committed Oct 1, 2024
1 parent 364174d commit e9944e7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/logic/createFormControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,8 @@ export function createFormControl<

const register: UseFormRegister<TFieldValues> = (name, options = {}) => {
let field = get(_fields, name);
const disabledIsDefined = isBoolean(options.disabled);
const disabledIsDefined =
isBoolean(options.disabled) || isBoolean(props.disabled);

set(_fields, name, {
...(field || {}),
Expand All @@ -1028,7 +1029,9 @@ export function createFormControl<
if (field) {
_updateDisabledField({
field,
disabled: options.disabled,
disabled: isBoolean(options.disabled)
? options.disabled
: props.disabled,
name,
value: options.value,
});
Expand All @@ -1037,7 +1040,9 @@ export function createFormControl<
}

return {
...(disabledIsDefined ? { disabled: options.disabled } : {}),
...(disabledIsDefined
? { disabled: options.disabled || props.disabled }
: {}),
...(_options.progressive
? {
required: !!options.required,
Expand Down

0 comments on commit e9944e7

Please sign in to comment.