GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rpearce/react-expanding-textarea: React textarea component to automatically expand and contract your textareas.

This repository was archived by the owner on Jun 30, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

206 Commits
206 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.storybook
.storybook
 
 
__tests__
__tests__
 
 
source
source
 
 
stories
stories
 
 
.all-contributorsrc
.all-contributorsrc
 
 
.eslintignore
.eslintignore
 
 
.eslintrc.js
.eslintrc.js
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
jest.config.js
jest.config.js
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.base.json
tsconfig.base.json
 
 
tsconfig.cjs.json
tsconfig.cjs.json
 
 
tsconfig.esm.json
tsconfig.esm.json
 
 
tsconfig.json
tsconfig.json
 
 
tsconfig.umd.json
tsconfig.umd.json
 
 

Repository files navigation

⚠️ Retired

Please consider using https://github.com/Andarist/react-textarea-autosize. There's an insurmountable issue with this approach in #82 that is solved by react-textarea-autosize.

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.

Links

  • Installation
  • Usage
  • Using The rows Prop
  • Manually Calling resize
  • Changelog
  • Contributing
  • Code of Conduct

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

🤔

jeffreystorer

🐛

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

About

React textarea component to automatically expand and contract your textareas.

rpearce.github.io/react-expanding-textarea/

Topics

autosizeexpanding-textareahacktoberfestreactreact-componentreactjstext-resizetextareatextarea-autoresizetextarea-componenttypescript

Resources

Readme
BSD-3-Clause license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

90 stars

Watchers

1 watching

Forks

13 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.