payload icon indicating copy to clipboard operation
payload copied to clipboard

pathFromProps inaccessible from RelationshipField component.

Open revnelson opened this issue 1 year ago • 0 comments

Describe the Bug

On line 118 of the RelationshipField component, the useField hook gets its path from pathFromContext and only pathFromProps if the former isn't available. It seems that a path passed explicitly as a prop should take precedent. I'm making a custom component of a group field where a relationship field is in the group. Because of this, the context path is that of the group. Passing in the correct path doesn't help because of the order mentioned above. I propose the following change:

  const {
    filterOptions,
    formInitializing,
    formProcessing,
    initialValue,
    path,
    setValue,
    showError,
    value: value_0
  } = useField({
    path: pathFromProps ?? pathFromContext ?? name,
    validate: memoizedValidate
  });

Link to the code that reproduces this issue

null

Reproduction Steps

Use a custom component for a field (i.e. group) that has a relationship field embedded. Try to use the exported RelationshipField component within the custom parent component. The RelationshipField component will incorrectly use the parent's field from context.

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

beta-116

revnelson avatar Oct 21 '24 22:10 revnelson