Comments (13)
I can repro with throttling x6. Accepting as a bug and adding the ready-to-take label.
from material-ui.
@ZeeshanTamboli do you know if this might be related to the recent TextareaAutosize
fixes?
from material-ui.
do you know if this might be related to the recent
TextareaAutosize
fixes?
Doesn't look related to the recent TextareaAutosize fixes. And I cannot reproduce the issue:
issue-42520.mp4
from material-ui.
@ZeeshanTamboli Try open the devtools and disable cache.
In your video, 0.01 to 0.03 reproduce the issue, check your video carefully
from material-ui.
@ZeeshanTamboli You can more easily to reproduce by using performance throttle to slow down performance:
from material-ui.
chrome126 support throttling x20 😄
from material-ui.
This may be expected behavior. The field cannot know how tall the rendered rows of text will be without rendering a line of text client-side, which would always result in a CLS problem.
Potential solutions
- The developer provides a hint to TextareaAutosize about how tall one line would be, which could populate the initial render.
- TextareaAutosize has an option to not resize until the first user interaction. This eliminates the CLS problem but makes the component "wiggly" to use.
- Developer uses
sx
to set a minimum height when CLS matters.
General note
The offending code seems to be around here: https://github.com/mui/material-ui/blob/master/packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx#L71
from material-ui.
Some cases can use minHeight, but sometimes the initial height is large than final actual height.
I had to use maxHeight
and remove the limit after after render:
import { TextField } from '@mui/material';
export default function MuiTextareaMinRows() {
const ref = useRef(null);
const [maxHeight, setMaxHeight] = useState('43px');
useEffect(() => {
if (typeof window !== 'undefined') {
setTimeout(() => {
setMaxHeight('unset');
}, 500);
}
}, []);
return (
<TextField
sx={{
'marginTop': 3,
'& > .MuiInputBase-multiline': {
p: '10px 12px',
},
maxHeight,
'& .MuiOutlinedInput-root': {
maxHeight,
},
}}
size="small"
placeholder="Anything you’d like to exclude?"
multiline
minRows={1}
fullWidth
/>
);
}
from material-ui.
If I use minHeight the placeholder
text will change position:
export default function MuiTextareaMinRows() {
const [maxHeight, setMaxHeight] = useState('43px');
useEffect(() => {
if (typeof window !== 'undefined') {
setTimeout(() => {
setMaxHeight('unset');
}, 500);
}
}, []);
return (
<>
<TextField
multiline
minRows={4}
placeholder="e.g. A cat is sitting on a table"
fullWidth
sx={{
'& > .MuiInputBase-multiline': {
minHeight: '149px',
},
}}
/>
<TextField
sx={{
'mt': 2,
'& > .MuiInputBase-multiline': {
maxHeight,
p: '10px 12px',
},
}}
size="small"
placeholder="Anything you’d like to exclude?"
multiline
minRows={1}
fullWidth
/>
</>
);
}
2024-07-11.01.04.09.mov
from material-ui.
@tjx666 I have handled this in the past by using minHeight
in sx
and not using minRows
. You can set the value in terms of em
units with help from lineHeight
to be exactly what minRows
would be without using the client side JS.
from material-ui.
@mi-na-bot can you provide a piece of simple code to demo?
from material-ui.
@tjx666 It depends on understanding the styling. There are two cases, whether the line-height
is set as a scalar or a value with units. Hope this helps!
https://codesandbox.io/p/sandbox/polished-surf-c5x353
from material-ui.
Thanks your help @mi-na-bot I also decide give up official minRows property and set the minHeight/maxHeight manually
from material-ui.
Related Issues (20)
- [docs][material-ui][Autocomplete] Wrong background color applied to gihub label demo HOT 2
- Constant refreshing of website in firefox firefox version 129.0.2 (64-bit) HOT 3
- [docs] Dark Background Only in Breadcrumbs Page HOT 3
- [Tabs] color prop should not be available as it is ignored HOT 1
- [material-ui][theme] Wrong `cssVariables` type in Theme interface HOT 1
- [material-ui][Autocomplete] Adding custom props to slotProps.paper in AutoComplete throws an error HOT 2
- [material-ui][Box] How can I use a styled api to add more props? HOT 3
- [material-ui][Skeleton] Error when using animation="wave"
- Input components fail to build with Pigment CSS without `cssVariables` HOT 5
- [material-ui][IconButton] `disableRipple` on `MuiButtonBase` doesn't disable ripple effect on `IconButton` HOT 2
- [material-ui][Button] Broken ripple effect with Pigment CSS HOT 6
- Enabling cssVariables with dark mode on is changing the color of AppBar HOT 1
- [material-ui][Grid] codemod not updating Grid HOT 2
- [Mui v6] Set default mode at first render HOT 5
- CssVarsProvider is deprecated but seems to be required to use useColorScheme() when creating a theme with createTheme() HOT 5
- [icons] Breaking changes in icons package layout
- Example is not working: https://github.com/mui/material-ui/tree/master/examples/material-ui-pigment-css-nextjs-ts HOT 2
- [material-ui][Dialog] maxWidth exceeds in v6 HOT 1
- [docs] Theme 'light' is not working HOT 1
- Icons for well-known and widespread applications HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui.