All Projects → javierjulio → Textarea Autosize

javierjulio / Textarea Autosize

Licence: mit
Vertically adjust a textarea based on user input without using a clone or ghost element.

Labels

Projects that are alternatives of or similar to Textarea Autosize

Stylelint Config Sass Guidelines
⚙ A stylelint config inspired by https://sass-guidelin.es/
Stars: ✭ 349 (-12.75%)
Mutual labels:  scss
Wxapp Boilerplate
使用 webpack, babel, scss 开发的微信/支付宝小程序项目脚手架
Stars: ✭ 367 (-8.25%)
Mutual labels:  scss
Typesettings
A Sass or Stylus toolkit that sets type in Ems based on modular scale, vertical rhythm, and responsive ratio based headlines.
Stars: ✭ 380 (-5%)
Mutual labels:  scss
Serverless Stack Com
An open source guide for building and deploying full-stack apps using Serverless and React on AWS.
Stars: ✭ 3,617 (+804.25%)
Mutual labels:  scss
Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+829.5%)
Mutual labels:  scss
Magento2 Theme Blank Sass
SASS based version of Magento 2 Blank theme
Stars: ✭ 373 (-6.75%)
Mutual labels:  scss
Rust Ffi Omnibus
A collection of examples of using code written in Rust from other languages
Stars: ✭ 344 (-14%)
Mutual labels:  scss
Umy Ui
umy-ui,一套为开发者准备的基于 Vue 2.0 的桌面端组件库,完美解决表格万级数据渲染卡顿,编辑表格卡顿问题
Stars: ✭ 396 (-1%)
Mutual labels:  scss
React Pro Sidebar
Customizable and responsive react sidebar library with dropdown menus and unlimited number of nested submenus
Stars: ✭ 359 (-10.25%)
Mutual labels:  scss
Repl
The Learning Hub for UoL's Online CS Students
Stars: ✭ 367 (-8.25%)
Mutual labels:  scss
Mappy Breakpoints
Breakpoints with Maps in Sass
Stars: ✭ 360 (-10%)
Mutual labels:  scss
The Shell
Ghost Theme 👻
Stars: ✭ 362 (-9.5%)
Mutual labels:  scss
Arewegameyet
The repository for arewegameyet.rs
Stars: ✭ 372 (-7%)
Mutual labels:  scss
React Coding Challenges
A collection of React.js coding challenges with different difficulties.
Stars: ✭ 294 (-26.5%)
Mutual labels:  scss
Trunk
Build, bundle & ship your Rust WASM application to the web.
Stars: ✭ 378 (-5.5%)
Mutual labels:  scss
Jekyll Theme Prologue
A Jekyll version of the "Prologue" theme by HTML5 UP
Stars: ✭ 346 (-13.5%)
Mutual labels:  scss
Office Ui Fabric Core
The front-end CSS framework for building experiences for Office and Microsoft 365.
Stars: ✭ 3,678 (+819.5%)
Mutual labels:  scss
Adminkit
🧰 AdminKit is a free & open source Bootstrap 5 Admin Template
Stars: ✭ 395 (-1.25%)
Mutual labels:  scss
Motherplate
A bare bones responsive SCSS boilerplate for web designers
Stars: ✭ 392 (-2%)
Mutual labels:  scss
Hacktoberfest2019
Happy Hacktober! This is a beginner friendly repository made specifically for Hacktoberfest that helps you get your first PR.
Stars: ✭ 378 (-5.5%)
Mutual labels:  scss

textarea-autosize

This is a jQuery plugin for vertically adjusting a textarea based on user input and controlling any presentation in CSS. No clone or ghost elements used. 😉

So why build this? Many solutions didn't feel smooth. In some the textarea would flicker on entering new lines with a noticeable delay in resizing. Most were outdated and all were a lot bulkier than they had to be. Many had to use a mirror textarea or ghost element with some needing presentation values set in script. I wanted just the behavior in the script and anything regarding presentation should be controlled through CSS.

Installation

NPM

npm install textarea-autosize

Bower

bower install textarea-autosize

Or add textarea-autosize to your application's bower.json.

  "dependencies": {
    "textarea-autosize": "latest"
  }

Standalone

curl -O https://raw.github.com/javierjulio/textarea-autosize/master/dist/jquery.textarea_autosize.js

Usage

Load the plugin and use jQuery to find the desired textarea elements on which to call the plugin method.

<textarea class="js-auto-size" rows="1"></textarea>

<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="jquery.textarea_autosize.min.js"></script>
<script>
  $('textarea.js-auto-size').textareaAutoSize();
</script>

Minimum CSS Requirements

The only requirement is to set box-sizing: border-box and a min-height on the textarea. In the example below, the minimum height is one line of text which is determined from the base font size, line height, and vertical padding and border.

textarea {
  box-sizing: border-box;
  max-height: 94px; /* optional, but recommended */
  min-height: 31px;
  overflow-x: hidden; /* for Firefox (issue #5) */
}

Increase the min-height to have more initial rows. Once text exceeds that minimum height the textarea will expand naturally. The overflow-x setting is for Firefox to prevent an initial additional line from appearing.

Updating Textarea Content

If you pre-fill the textarea before page load the textarea will adjust to fit automatically but if given a value after page load (e.g. single page app) then you will need to trigger an input event on the textarea after setting its value for it to size correctly.

textarea.val('A test comment.').trigger('input');

Browser Support

These are the browsers I've tested against. These are not requirements.

  • Google Chrome (latest)
  • Apple Safari 6+
  • Mozilla Firefox (latest)
  • Internet Explorer 9+ (using ievms)

Contributions

Project setup: npm install

Run tests: npm test

Deploy New Release

Replace {type} with any of the following: patch, minor or major

npm version {type} --no-git-tag-version
bower version {type} -m "Prep %s release"
git push origin --tags
npm publish

Update GitHub Project Page

  git push origin master
  git push -f origin origin/master:gh-pages

Version History

0.4.2 (March 30, 2016)

  • Account for vertical border width (#18 - thanks @kulbakin)
  • Remove unused variable (#16 - thanks @nomosyn)

0.4.1 (May 7, 2015)

  • Default to 0 if no vertical padding set (#11 - thanks @pedroha)

0.4.0 (December 18, 2014)

  • Preserving window scroll position whenever textarea height changes (Issue #6)
  • Updated suggested CSS to include overflow-x hidden (Issue #5)
  • Removed code that accounted for Firefox height issue
  • Updated demo sample code to reflect values used for single line textarea

0.3.0 (September 15, 2014)

  • Updated demo to use SASS

0.2.0 (June 3, 2014)

  • Minor README changes
  • Updated gulp related dev dependencies

0.1.0 (April 19, 2014)

  • Initial release

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].