swordev / suid

A port of Material-UI (MUI) built with SolidJS.
https://suid.io
MIT License
660 stars 47 forks source link

Height of multiline textfield "jumps around" when element is created outside of DOM #250

Open evertheylen opened 1 year ago

evertheylen commented 1 year ago

In my app I create components outside of the DOM sometimes, only inserting them into the DOM when necessary. This seems to collide with the logic behind <Textfield multiline/>. More specifically, the textfield's height is way too small, and then jumps to the desired height.

Here is a minimal demo: https://stackblitz.com/edit/tz3p3n?file=src%2FApp.tsx

I believe this code has something to do with it:

if (computedStyle.width === "0px") {
  return;
}

If the element is not inserted into the DOM yet, it appears that all attributes of computedStyle are empty strings. Changing the code to the following helps a bit:

if (computedStyle.width === "0px" || computedStyle.width === "") {
  return;
}

But now the textfield seems to jump from slightly more than the desired height to the actual desired height, still giving a jarring user experience.

evertheylen commented 1 year ago

(As a workaround, I'm currently using InputProps={{style: "min-height: 1234px"}} where 1234px is the height of the element after it "jumped" and has the correct height. Of course, this is rather brittle.)