react-hook-form 7.56.4 → 7.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -264,7 +264,7 @@ function useFormState(props) {
264
264
  errors: false,
265
265
  });
266
266
  useIsomorphicLayoutEffect(() => control._subscribe({
267
- name: name,
267
+ name,
268
268
  formState: _localProxyFormState.current,
269
269
  exact,
270
270
  callback: (formState) => {
@@ -317,7 +317,7 @@ function useWatch(props) {
317
317
  const _defaultValue = React__default.useRef(defaultValue);
318
318
  const [value, updateValue] = React__default.useState(control._getWatch(name, _defaultValue.current));
319
319
  useIsomorphicLayoutEffect(() => control._subscribe({
320
- name: name,
320
+ name,
321
321
  formState: {
322
322
  values: true,
323
323
  },
@@ -414,8 +414,8 @@ function useController(props) {
414
414
  const field = get(control._fields, name);
415
415
  if (field && elm) {
416
416
  field._f.ref = {
417
- focus: () => elm.focus(),
418
- select: () => elm.select(),
417
+ focus: () => elm.focus && elm.focus(),
418
+ select: () => elm.select && elm.select(),
419
419
  setCustomValidity: (message) => elm.setCustomValidity(message),
420
420
  reportValidity: () => elm.reportValidity(),
421
421
  };
@@ -992,6 +992,12 @@ function schemaErrorLookup(errors, _fields, name) {
992
992
  error: foundError,
993
993
  };
994
994
  }
995
+ if (foundError && foundError.root && foundError.root.type) {
996
+ return {
997
+ name: `${fieldName}.root`,
998
+ error: foundError.root,
999
+ };
1000
+ }
995
1001
  names.pop();
996
1002
  }
997
1003
  return {
@@ -1615,7 +1621,7 @@ function createFormControl(props = {}) {
1615
1621
  return;
1616
1622
  }
1617
1623
  const fieldValue = value[fieldKey];
1618
- const fieldName = `${name}.${fieldKey}`;
1624
+ const fieldName = name + '.' + fieldKey;
1619
1625
  const field = get(_fields, fieldName);
1620
1626
  (_names.array.has(name) ||
1621
1627
  isObject(fieldValue) ||
@@ -2214,6 +2220,7 @@ function createFormControl(props = {}) {
2214
2220
  setError,
2215
2221
  _subscribe,
2216
2222
  _runSchema,
2223
+ _focusError,
2217
2224
  _getWatch,
2218
2225
  _getDirty,
2219
2226
  _setValid,
@@ -2673,10 +2680,13 @@ function useForm(props = {}) {
2673
2680
  if (props.reValidateMode) {
2674
2681
  control._options.reValidateMode = props.reValidateMode;
2675
2682
  }
2676
- if (props.errors && !isEmptyObject(props.errors)) {
2683
+ }, [control, props.mode, props.reValidateMode]);
2684
+ React__default.useEffect(() => {
2685
+ if (props.errors) {
2677
2686
  control._setErrors(props.errors);
2687
+ control._focusError();
2678
2688
  }
2679
- }, [control, props.errors, props.mode, props.reValidateMode]);
2689
+ }, [control, props.errors]);
2680
2690
  React__default.useEffect(() => {
2681
2691
  props.shouldUnregister &&
2682
2692
  control._subjects.state.next({