Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-expanding-textarea

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-expanding-textarea

React textarea component to automatically expand and contract your textareas

  • 2.3.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
increased by2.33%
Maintainers
1
Weekly downloads
 
Created
Source

react-expanding-textarea

All Contributors npm version npm downloads bundlephobia size

React textarea component to automatically expand and contract your textareas.

You can view the demo here.

Installation

npm i react-expanding-textarea

Usage

Use this exactly like you would a normal <textarea>; the only difference is that it is doing some simple expanding work behind the scenes for you!

import React, { useCallback, useEffect, useRef } from 'react'
import Textarea from 'react-expanding-textarea'

const MyTextarea = () => {
  const textareaRef = useRef(null)

  const handleChange = useCallback(e => {
    console.log('Changed value to: ', e.target.value)
  }, [])

  useEffect(() => {
    textareaRef.current.focus()
  }, [])

  return (
    <>
      <label htmlFor="my-textarea">
        Please Enter Some Details:
      </label>
      <Textarea
        className="textarea"
        defaultValue="Lorem ipsum dolor sit amet, ..."
        id="my-textarea"
        maxLength="3000"
        name="pet[notes]"
        onChange={handleChange}
        placeholder="Enter additional notes..."
        ref={textareaRef}
      />
    </>
  )
}

Using The rows Prop

If you pass a rows prop, then this component will perform a calculation based on computed lineHeight, borderTopWidth, borderBottomWidth, paddingTop and paddingBottom to deduce what the minimum height-in-rows the component should be.

Manually Calling resize

If for some reason you need to manually resize a <textarea>, this package exports a resize function that has the following type:

interface Resize {
  (rows: number, el: HTMLTextAreaElement | null): void
}

And you can use it like this:

import { resize } from 'react-expanding-textarea'

// resize based on 3 minimum rows
// and using a React ref
resize(3, refTextarea.current)

// or

// resize based on no minimum rows
// and using a regular DOM Node
resize(0, document.querySelector('textarea'))

Contributors

Thanks goes to these wonderful people (emoji key):


Robert Pearce

💻 📖 💡 🤔 ⚠️

Anuj

🐛

Lloyd Watkin

🤔

Jordan Hornblow

🐛

visgotti

🤔

Thomas Sunde Nielsen

🐛 🤔

cibulka

🐛 🤔

Brett Smith

🐛

Rauno Freiberg

🐛 💻

Thomas Kristiansen

🤔

Puspender

🐛

Mark Thomas

🐛

Artem

🐛

Eva Raymond

🐛

Chris Drackett

🐛

Simon Smith

🐛 🤔 👀

jordie23

🐛 🤔

Mat Sz

🐛 💻

crtl

🐛 🤔

Jonathan Wan

🐛 💻

James Moss

🐛 🤔

SunnyAureliusRichard

🐛

Magoz

🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Package last updated on 25 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc