question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TextArea is wrong size initially (off by a hair), then it adjusts as you type?

See original GitHub issue

I have a <TextareaAutosize> used with react-hook-form, and when it starts out, the textarea is slightly smaller than it should be. When I type, it fixes. What should I do to fix this? Is it the font that is throwing it off, or my CSS or something?

Here is a gif.

2021-11-04 01 48 58

Here is a snippet of my code from a larger project:

import TextareaAutosize from 'react-textarea-autosize'
import styles from './index.module.css'
import { Controller } from 'react-hook-form'

export default function TextField({
  label,
  placeholder,
  type,
  value,
  inputId,
  control,
  prefix,
  name,
  minHeight,
  ...props
}) {
  return (
    <div className={styles.field}>
      <label className={styles.label}>{label}</label>
      <div className={styles.inputContainer}>
        <Controller
          name={name}
          control={control}
          render={({ field }) => (
            <TextareaAutosize {...field} minRows={minHeight} className={styles.input} placeholder={placeholder} />
          )}
        />
      </div>
    </div>
  )
}

And usage like this:

function Details() {
  const { handleSubmit, control } = useForm()

  const onSubmit = (data) => {
    console.log(data)
  }

  return (
    <form className={styles.form} onSubmit={handleSubmit(onSubmit)}>
      <legend className={styles.legend}>Details</legend>
      <TextField minHeight={4} control={control} name="blurb" label="Blurb" placeholder="Love to learn and make!" />
      <div className={styles.actions}><button className={styles.button} type="submit">Save</button></div>
    </form>
  )
}

The CSS for the file is here:

.field {
  padding-bottom: 20px;
}

.label {
  opacity: 0.7;
  font-size: 14px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.image {
  width: 100px;
  height: 100px;
  background: #eee;
  margin-right: 20px;
}

.imageContainer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.removeUploadButton {
  display: flex;
  cursor: pointer;
}

.addButton {
  display: flex;
  cursor: pointer;
}

.removeButton {
  display: flex;
  left: -6px;
  cursor: pointer;
}

.inputContainer {
  display: flex;
  padding: 10px 20px;
  margin: 10px 0px;
  background: #eee;
  width: 100%;
  border-radius: 4px;
  font-size: 22px;
}

.input {
  flex: 1;
}

.input::placeholder, .inputPrefix {
  color: #aaa;
}

.legend {
  text-transform: uppercase;
  font-size: 22px;
  opacity: 0.7;
}

.imageContent {
  display: flex;
  align-items: center;
}

.button {
  cursor: pointer;
  padding: 10px 20px;
  color: white;
  background: #777;
  border-radius: 4px;
  text-align: center;
  width: 200px;
}

Any ideas?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raduflpcommented, Jan 28, 2022

@Andarist could not reproduce it for simple scenarios, but was able to reproduce it with @headlessui/react Transition Inspecting the broken scenarios you can see that the textarea style doesn’t have a height set compared to the working scenarios. Hope that helps

https://codesandbox.io/s/clever-shtern-uw09l-uw09l

1reaction
Andaristcommented, Nov 19, 2021

Please always try to share a repro case in a runnable form - either by providing a git repository to clone or a codesandbox. OSS maintainers usually can’t afford the time to set up the repro, even if exact steps are given.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible to have an initial width of textarea but leave it ...
It can be made bigger, but not smaller than the width that is originally placed in the style of the textarea. Height works...
Read more >
How to Disable the Resizing of the <textarea> Element?
In this article, we are going to learn how to make the HTML <textarea> element have a fixed, unchangeable size. To prevent a...
Read more >
94583 - Textarea resize-able only to larger; min-height and ...
This should be incredibly simple to fix. Obviously the bounds of resize are set at initialization with the minimum size always set to...
Read more >
PySimpleGUI
This allows you to easily access and make changes to your Pi without having ... The way I use it is to first...
Read more >
The Textarea element - HTML: HyperText Markup Language
hard : The browser automatically inserts line breaks (CR+LF) so that each line is no longer than the width of the control; the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found