Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting values asynchronously in form context does not update the label #44459

Open
falk-stefan opened this issue Nov 18, 2024 · 1 comment
Open
Assignees
Labels
component: text field This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information

Comments

@falk-stefan
Copy link

falk-stefan commented Nov 18, 2024

Steps to reproduce

I am using react-form in combination with the TextField component:

const { register, handleSubmit, reset, formState, watch, setValue } = useForm({
  mode: 'all',
  defaultValues: {
    [label]: value,
  },
});

// ..
<TextField {...register(label, { ...validation })} />

The problem: If value is loaded asynchrounously, the label on top of the text component won't move to the top:

image

I've already tried to setValue:

useEffect(() => {
  setValue(label, value);
}, [label, setValue, value]);

but that didn't work either. It looks like TextField is not reacting to the underlying value changing? Or is this something that's caused by react-form?

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: useform, textfield, label

@falk-stefan falk-stefan added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 18, 2024
@mj12albert
Copy link
Member

@falk-stefan Do you mean react-hook-form?
BTW could you share a repro (eg in Codesandbox)?

@mj12albert mj12albert added component: text field This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 19, 2024
@DiegoAndai DiegoAndai moved this to Backlog in Material UI Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information
Projects
Status: Backlog
Development

No branches or pull requests

2 participants