-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
TextField Outline Legend width does not get calculated correctly on label prop change #16833
Comments
@ASHFAQPATWARI There are a couple of related issues:
|
@oliviertassinari This is not a duplicated issue. It seems similar to issues mentionedby you but in my case, adding key prop also does not help as application is becoming LTR/RTL with language switch and legend width calculation is not correct as shown in attached image |
@ASHFAQPATWARI Do you have a reproduction? |
@ASHFAQPATWARI Thanks, it's a bug with our styling solution. You can work around the problem with |
@oliviertassinari The bug doesn't appear if i put |
@oliviertassinari Putting the key prop results in reference being updated and form validations doesn't work. Have a look at this: react-hook-form/react-hook-form#177 |
happy to assist and provide information here. |
@oliviertassinari - The main issue I see is the effect that sets the label width does not re-execute when the label changes. The diff --git a/packages/material-ui/src/TextField/TextField.js b/packages/material-ui/src/TextField/TextField.js
index 9f595cca402..5731270e405 100644
--- a/packages/material-ui/src/TextField/TextField.js
+++ b/packages/material-ui/src/TextField/TextField.js
@@ -99,7 +99,7 @@ const TextField = React.forwardRef(function TextField(props, ref) {
const labelNode = ReactDOM.findDOMNode(labelRef.current);
setLabelWidth(labelNode != null ? labelNode.offsetWidth : 0);
}
- }, [variant, required]);
+ }, [variant, required, label]);
warning(
!select || Boolean(children), Here is a codesandbox demonstrating a fixed version alongside the current version as the label changes (by clicking the button). FYI - I found this issue after seeing a StackOverflow question related to this problem. |
@ryancogswell We have left the label out of the dependency array to discourage people from changing it. But I think that you are right. It's another possible solution, +1 for going for it. @ASHFAQPATWARI Do you want to submit a pull request? :) |
@oliviertassinari I will not be able to submit a pull request. I am running with very tight deadlines |
No problem, maybe somebody else will :). |
@oliviertassinari is using the |
No, this trick is no longer needed with the latest version. |
is this fix in V4? I tried adding key and all, but I still get border crossing the label. |
@LavaGolem Try on v5.0.0-beta.1 |
Hi so two things
as I said adding key didn't solve the issue, also this TextField is used inside of Field component, not sure if it is relevant |
Hey, I found a solution that works fine!! |
Spent longer than I thought I would on this and this was the solution for me, thanks. Given there's no class on the legend wasn't sure how to add a rule in the theme so went and added this to css file:
|
use input like this example
|
The border of a TextField with variant="outlined" does not update correctly when new label props are being passed into the component on language change. I am using key prop which changes on language change and this makes my input legend to render again but with wrong calculations
Expected Behavior 🤔
The width of legend should be calculated properly
Current Behavior 😯
The legend width is not calculated correctly.
Initial render:
After language switch:
Steps to Reproduce 🕹
Link:
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: