m4r71n / react-expanding-textarea

React textarea component to automatically expand and contract your textareas.

Home Page:http://rpearce.github.io/react-expanding-textarea/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Install the package:

$ npm i react-expanding-textarea

or

$ yarn add 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 for="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.

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

πŸ› πŸ€”

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

About

React textarea component to automatically expand and contract your textareas.

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

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:TypeScript 80.6%Language:JavaScript 16.3%Language:CSS 3.1%