-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[OutlinedInput] Label width is being calculated before fonts are loaded #16465
Comments
We have a similar issue with the Tabs component: #7187. I'm not aware of any better solution than the ones we have explored in the tab linked issue. To sum-up:
|
I dug into FontFaceObserver, and I found a solution I loaded the font first and returned a promise that resolves when the font is loaded then renders the page |
If you want a very simple solution to handle this and don't mind using experimental technology that is currently supported by most browsers here is an example...
|
Thank you @stevenberdak, I ll try it as soon as possible, if you are interested on knowing how I got it to work, here is how:
import FontFaceObserver from 'fontfaceobserver';
const appFont = new FontFaceObserver('NAME_OF_FONT');
appFont.load().then(() => {
ReactDOM.render(rootElement, document.getElementById('root'))
}) Note that rootElement is a variable wrapping my |
We have explored a solution in #17680 that only relies on CSS to position the label. This should solve the problem. |
My solution with version 5. /* start: change outline fiels label text size */
MuiInputLabel: {
styleOverrides: {
outlined: {
'&$shrink': {
transform: 'translate(14px, -6px) scale(0.9)',
},
},
},
},
MuiOutlinedInput: {
styleOverrides: {
notchedOutline: {
'& > legend': {
fontSize: ' 0.9em',
},
},
},
},
/* end: change outline fiels label text size */ |
Thank you @sebascomeau, your solution for v5 worked for me. |
I'm facing this issue when I update the font-size and font-weight and using Futura-Bt medium fonts. |
I tried to set the width for the legend when I changed the font-family and font-size using this:
But I'm not sure that the width is calculated correctly. |
Expected Behavior 🤔
What should happen is the following
![Screenshot_1](https://user-images.githubusercontent.com/37586909/60589536-a70d5b80-9d91-11e9-9aa7-2dc2f6302046.png)
Current Behavior 😯
But instead I get this
![Screenshot_2](https://user-images.githubusercontent.com/37586909/60589629-e0de6200-9d91-11e9-8387-deb7fa6c1c96.png)
Notice that the TextField's outline is slightly overlaping the label.
This only happens when the page loads for the first time (Or after a hard refresh), and whenever a react re-render occurs, the problem is gone.
I also noticed that this problem happened when I changed the default font, and I think it has something to do with FOUT (Flash of unstyled text).
Is it possible that Mui calculates the label's gap width on the outline based on the font that loads first, before the new font style gets applied
PS: When I write something with Roboto font, then I change the font family to something else (in this case Tajawal) and give them the same font size, I notice that the same sentence I typed with Tajawal is a bit wider than the one with Roboto.
Can anyone help me solve this issue, and is there a way to load font styles before React manifests into the root element?
Your Environment 🌎
The text was updated successfully, but these errors were encountered: