-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
TextInput Label doesn't shrink when filling from inputRef #17018
Comments
Are you sure about the reproduction? I don't see any issue. |
@oliviertassinari Yes, I might have forgotten to save the code the codesandbox. Please check it again. The placeholder is overlapping the text. |
Could the problem come from #16526? |
This comment has been minimized.
This comment has been minimized.
I don't understand why that library needs to mutate the value in the DOM instead of using Using |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
hi @eps1lon, Yes you can set eg: This library itself have to mutate the input |
|
It's more of a DX thing, like I mentioned above when dev wants to declare all default values in one go. The library allows them to write things like
during |
But why do you need to go outside of react to change the value? We already have all the tools in place to solve these issues. We specifically want to avoid mutating the instance from outside because this can cause all sorts of unforeseen issues. Especially when you're building a brand new library using hooks there's really no need to go back to handling state via DOM. If your concern is DX you could just as well use |
The more I look at this the more I feel like using By having name and defaultValue at the component I have those next to each other and eliminate potential bugs when mispelling/renaming names or keys. |
First of all, thanks for the feedback :)
In this instance, I couldn't see an issue when setting up the default value. It leverages the native DOM API and it's not "outside" (it using component ref).
I disagree with the above statement, it's not the intention for this library to "look" faster. The intention is great DX and better performance (it can be). I don't want to go for syntax like I guess the solution right now is to trigger an extra re-render when user changing |
Totally agree, one of the reasons we had typescript support to declare a type, so avoid misspell the name. |
Well I'm happy to hear your reasoning but if you don't want to discuss this we can close the issue. I'll wait a bit in case someone else has other arguments.
Could you share some benchmarks so that we can evaluate if it would make sense to support this API?
This sounds interesting. How do you make sure I can't write |
It's a design decision which I made when I start building react hook form. I prefer things to be more declarative so devs can see each prop. Not a big fan of
sure, do you mean overall performance enhancement of this library or just setting up defaultValue? When I made my statement above, I meant overall. If you are interested in terms of overall performance enhancement, I have a couple of screenshot on the website: https://react-hook-form.com
This is what we have at the moment, this library is still very young and we are still consistently improving on the type and everything else. I don't think we can prevent everything but at least we try :) By the way, my intention was not to ask MUI to make a change for react-hook-form, rather than find a solution in between. |
Would |
@minhaferzz no :( |
I'm closing, following #17025 (comment). @bluebill1049 let us know if you see more people facing this issue, we could revaluate in the future. |
Thanks @oliviertassinari and @eps1lon anyhow for looking into this. |
I'm having a similar issue as this, but it's unclear if it's the same or different. I'm using |
@sdornan If you have a minimal live reproduction that show that the issue originates from Material-UI, e.g. using codesandbox, feel free to open a new issue. In the case of react-hook-form, we have already explored some of the issues with the approach the library took. More details in #18269 (comment). |
@sdornan please consider using Controller with MUI components. |
Here's a reproduction: https://codesandbox.io/s/hopeful-mountain-cgx6p Will open a new issue if necessary. |
@sdornan did you got this resolved? |
I manged to solve it by passing InputLabelProps and biding the "shrink" prop to the field's value. |
@bluebill1049 Using Controller does not work on Safari either. |
@rfoel I don't think so. Provide a code sandbox and screenshots/video. |
@gradinarot I did the same thing as you. |
I know this is old, but how did you do it? passing state value and useEffect? ... I'm working in the same direction |
Read the documentation. https://react-hook-form.com/api/usecontroller/controller CSB: https://codesandbox.io/s/react-hook-form-v7-controller-5h1q5 |
Put something like this on your TextField. InputLabelProps={{ |
@bluebill1049, I know this is an old thread, but is there a way to solve this issue without the controller? TextField stutters with the controlled input, so it would be great if there was a way, even if hacky, to make the components' labels shrink back. |
I had the same problem, here’s how I fixed the bug 🥳 import {Controller} from "react-hook-form";
import {TextField} from "@mui/material";
import Cleave from "cleave.js/react";
import React from 'react'
import 'cleave.js/dist/addons/cleave-phone.fr'
const CleaveTextField = React.forwardRef((props, ref) => (
<Cleave htmlRef={ref} {...props} />
));
/**
* @param name
* @param control
* @param label
* @param required
* @returns {JSX.Element}
* @constructor
*/
const PhoneField = ({ name, control, label, required }) => {
return (
<Controller
name={name}
control={control}
render={({ field, formState,}) => {
const errorMessage = formState.errors[name]?.message || '';
return <TextField
{...field}
label={label}
error={!!errorMessage}
helperText={errorMessage as string}
fullWidth
placeholder='00 00 00 00 00'
required={required}
InputProps={{
inputComponent: CleaveTextField
}}
inputProps={{
options: {
phone: true,
phoneRegionCode: 'FR',
}
}} />
}} />
);
};
export default PhoneField; |
The Label Shrinks if you wrap the input component with Controller and pass the value into it.
|
When I'm using react-hook-form to set some values in a TextInput I receive from the server, it populates correctly, but doesn't shrink the label.
Current Behavior 😯
Currently the text is overlapping the placeholder text.
Expected Behavior 🤔
The placeholder should shrink and display above the filled text.
Steps to Reproduce 🕹
https://codesandbox.io/s/react-hook-form-mui-textfield-3czpw
Context 🔦
This started happening in v4.2.1 and up. It works in v4.2.0.
The text was updated successfully, but these errors were encountered: